2023-06-11 00:38:22

by kernel test robot

[permalink] [raw]
Subject: ld.lld: error: relocation R_RISCV_HI20 cannot be used against symbol 'misaligned_access_speed'; recompile with -fPIC

tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: 022ce8862dff83c859089cd14bc4dca0733e2f90
commit: 8dc2a7e8027fbeca0c7df81d4c82e735a59b5741 riscv: Fix relocatable kernels with early alternatives using -fno-pie
date: 10 days ago
config: riscv-randconfig-r022-20230611 (https://download.01.org/0day-ci/archive/20230611/[email protected]/config)
compiler: clang version 16.0.4 (https://github.com/llvm/llvm-project.git ae42196bc493ffe877a7e3dff8be32035dea4d07)
reproduce (this is a W=1 build):
mkdir -p ~/bin
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# install riscv cross compiling tool for clang build
# apt-get install binutils-riscv64-linux-gnu
# https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=8dc2a7e8027fbeca0c7df81d4c82e735a59b5741
git remote add linus https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
git fetch --no-tags linus master
git checkout 8dc2a7e8027fbeca0c7df81d4c82e735a59b5741
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang ~/bin/make.cross W=1 O=build_dir ARCH=riscv olddefconfig
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang ~/bin/make.cross W=1 O=build_dir ARCH=riscv SHELL=/bin/bash

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

>> ld.lld: error: relocation R_RISCV_HI20 cannot be used against symbol 'misaligned_access_speed'; recompile with -fPIC
>>> defined in vmlinux.a(arch/riscv/kernel/cpufeature.o)
>>> referenced by errata.c:42 (arch/riscv/errata/thead/errata.c:42)
>>> arch/riscv/errata/thead/errata.o:(thead_feature_probe_func) in archive vmlinux.a
--
>> ld.lld: error: relocation R_RISCV_LO12_I cannot be used against symbol 'misaligned_access_speed'; recompile with -fPIC
>>> defined in vmlinux.a(arch/riscv/kernel/cpufeature.o)
>>> referenced by errata.c:42 (arch/riscv/errata/thead/errata.c:42)
>>> arch/riscv/errata/thead/errata.o:(thead_feature_probe_func) in archive vmlinux.a
--
>> ld.lld: error: relocation R_RISCV_HI20 cannot be used against symbol 'riscv_cbom_block_size'; recompile with -fPIC
>>> defined in vmlinux.a(arch/riscv/mm/cacheflush.o)
>>> referenced by errata.c:42 (arch/riscv/errata/thead/errata.c:42)
>>> arch/riscv/errata/thead/errata.o:(thead_errata_patch_func) in archive vmlinux.a
--
>> ld.lld: error: relocation R_RISCV_LO12_S cannot be used against symbol 'riscv_cbom_block_size'; recompile with -fPIC
>>> defined in vmlinux.a(arch/riscv/mm/cacheflush.o)
>>> referenced by errata.c:42 (arch/riscv/errata/thead/errata.c:42)
>>> arch/riscv/errata/thead/errata.o:(thead_errata_patch_func) in archive vmlinux.a
--
>> ld.lld: error: relocation R_RISCV_HI20 cannot be used against symbol '__per_cpu_offset'; recompile with -fPIC
>>> defined in vmlinux.a(mm/percpu.o)
>>> referenced by errata.c:42 (arch/riscv/errata/thead/errata.c:42)
>>> arch/riscv/errata/thead/errata.o:(thead_feature_probe_func) in archive vmlinux.a
--
>> ld.lld: error: relocation R_RISCV_LO12_I cannot be used against symbol '__per_cpu_offset'; recompile with -fPIC
>>> defined in vmlinux.a(mm/percpu.o)
>>> referenced by errata.c:42 (arch/riscv/errata/thead/errata.c:42)
>>> arch/riscv/errata/thead/errata.o:(thead_feature_probe_func) in archive vmlinux.a

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki


2023-06-13 09:07:59

by Alexandre Ghiti

[permalink] [raw]
Subject: Re: ld.lld: error: relocation R_RISCV_HI20 cannot be used against symbol 'misaligned_access_speed'; recompile with -fPIC

On Sun, Jun 11, 2023 at 2:11 AM kernel test robot <[email protected]> wrote:
>
> tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
> head: 022ce8862dff83c859089cd14bc4dca0733e2f90
> commit: 8dc2a7e8027fbeca0c7df81d4c82e735a59b5741 riscv: Fix relocatable kernels with early alternatives using -fno-pie
> date: 10 days ago
> config: riscv-randconfig-r022-20230611 (https://download.01.org/0day-ci/archive/20230611/[email protected]/config)
> compiler: clang version 16.0.4 (https://github.com/llvm/llvm-project.git ae42196bc493ffe877a7e3dff8be32035dea4d07)
> reproduce (this is a W=1 build):
> mkdir -p ~/bin
> wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
> chmod +x ~/bin/make.cross
> # install riscv cross compiling tool for clang build
> # apt-get install binutils-riscv64-linux-gnu
> # https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=8dc2a7e8027fbeca0c7df81d4c82e735a59b5741
> git remote add linus https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
> git fetch --no-tags linus master
> git checkout 8dc2a7e8027fbeca0c7df81d4c82e735a59b5741
> # save the config file
> mkdir build_dir && cp config build_dir/.config
> COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang ~/bin/make.cross W=1 O=build_dir ARCH=riscv olddefconfig
> COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang ~/bin/make.cross W=1 O=build_dir ARCH=riscv SHELL=/bin/bash
>
> If you fix the issue in a separate patch/commit (i.e. not just a new version of
> the same patch/commit), kindly add following tags
> | Reported-by: kernel test robot <[email protected]>
> | Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
>
> All errors (new ones prefixed by >>):
>
> >> ld.lld: error: relocation R_RISCV_HI20 cannot be used against symbol 'misaligned_access_speed'; recompile with -fPIC
> >>> defined in vmlinux.a(arch/riscv/kernel/cpufeature.o)
> >>> referenced by errata.c:42 (arch/riscv/errata/thead/errata.c:42)
> >>> arch/riscv/errata/thead/errata.o:(thead_feature_probe_func) in archive vmlinux.a
> --
> >> ld.lld: error: relocation R_RISCV_LO12_I cannot be used against symbol 'misaligned_access_speed'; recompile with -fPIC
> >>> defined in vmlinux.a(arch/riscv/kernel/cpufeature.o)
> >>> referenced by errata.c:42 (arch/riscv/errata/thead/errata.c:42)
> >>> arch/riscv/errata/thead/errata.o:(thead_feature_probe_func) in archive vmlinux.a
> --
> >> ld.lld: error: relocation R_RISCV_HI20 cannot be used against symbol 'riscv_cbom_block_size'; recompile with -fPIC
> >>> defined in vmlinux.a(arch/riscv/mm/cacheflush.o)
> >>> referenced by errata.c:42 (arch/riscv/errata/thead/errata.c:42)
> >>> arch/riscv/errata/thead/errata.o:(thead_errata_patch_func) in archive vmlinux.a
> --
> >> ld.lld: error: relocation R_RISCV_LO12_S cannot be used against symbol 'riscv_cbom_block_size'; recompile with -fPIC
> >>> defined in vmlinux.a(arch/riscv/mm/cacheflush.o)
> >>> referenced by errata.c:42 (arch/riscv/errata/thead/errata.c:42)
> >>> arch/riscv/errata/thead/errata.o:(thead_errata_patch_func) in archive vmlinux.a
> --
> >> ld.lld: error: relocation R_RISCV_HI20 cannot be used against symbol '__per_cpu_offset'; recompile with -fPIC
> >>> defined in vmlinux.a(mm/percpu.o)
> >>> referenced by errata.c:42 (arch/riscv/errata/thead/errata.c:42)
> >>> arch/riscv/errata/thead/errata.o:(thead_feature_probe_func) in archive vmlinux.a
> --
> >> ld.lld: error: relocation R_RISCV_LO12_I cannot be used against symbol '__per_cpu_offset'; recompile with -fPIC
> >>> defined in vmlinux.a(mm/percpu.o)
> >>> referenced by errata.c:42 (arch/riscv/errata/thead/errata.c:42)
> >>> arch/riscv/errata/thead/errata.o:(thead_feature_probe_func) in archive vmlinux.a
>

So I looked into those errors, the config is basically = RELOCATABLE +
MEDLOW - EARLY_ALTERNATIVES. Then errata/thead is not compiled as
medany, which makes sense since we only need this code to be medany
when EARLY_ALTERNATIVES is enabled (because the code would be executed
with mmu off, which is not the case here).

I can fix those errors by adding the medany flag, but I'm not sure
actually we want to do that since we do not need it and gcc does not
complain: any idea?

Alex



> --
> 0-DAY CI Kernel Test Service
> https://github.com/intel/lkp-tests/wiki

2023-06-14 16:53:28

by Nick Desaulniers

[permalink] [raw]
Subject: Re: ld.lld: error: relocation R_RISCV_HI20 cannot be used against symbol 'misaligned_access_speed'; recompile with -fPIC

On Tue, Jun 13, 2023 at 4:17 AM Alexandre Ghiti <[email protected]> wrote:
>
> On Sun, Jun 11, 2023 at 2:11 AM kernel test robot <[email protected]> wrote:
> >
> > tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
> > head: 022ce8862dff83c859089cd14bc4dca0733e2f90
> > commit: 8dc2a7e8027fbeca0c7df81d4c82e735a59b5741 riscv: Fix relocatable kernels with early alternatives using -fno-pie
> > date: 10 days ago
> > config: riscv-randconfig-r022-20230611 (https://download.01.org/0day-ci/archive/20230611/[email protected]/config)
> > compiler: clang version 16.0.4 (https://github.com/llvm/llvm-project.git ae42196bc493ffe877a7e3dff8be32035dea4d07)
> > reproduce (this is a W=1 build):
> > mkdir -p ~/bin
> > wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
> > chmod +x ~/bin/make.cross
> > # install riscv cross compiling tool for clang build
> > # apt-get install binutils-riscv64-linux-gnu
> > # https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=8dc2a7e8027fbeca0c7df81d4c82e735a59b5741
> > git remote add linus https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
> > git fetch --no-tags linus master
> > git checkout 8dc2a7e8027fbeca0c7df81d4c82e735a59b5741
> > # save the config file
> > mkdir build_dir && cp config build_dir/.config
> > COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang ~/bin/make.cross W=1 O=build_dir ARCH=riscv olddefconfig
> > COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang ~/bin/make.cross W=1 O=build_dir ARCH=riscv SHELL=/bin/bash
> >
> > If you fix the issue in a separate patch/commit (i.e. not just a new version of
> > the same patch/commit), kindly add following tags
> > | Reported-by: kernel test robot <[email protected]>
> > | Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
> >
> > All errors (new ones prefixed by >>):
> >
> > >> ld.lld: error: relocation R_RISCV_HI20 cannot be used against symbol 'misaligned_access_speed'; recompile with -fPIC
> > >>> defined in vmlinux.a(arch/riscv/kernel/cpufeature.o)
> > >>> referenced by errata.c:42 (arch/riscv/errata/thead/errata.c:42)
> > >>> arch/riscv/errata/thead/errata.o:(thead_feature_probe_func) in archive vmlinux.a
> > --
> > >> ld.lld: error: relocation R_RISCV_LO12_I cannot be used against symbol 'misaligned_access_speed'; recompile with -fPIC
> > >>> defined in vmlinux.a(arch/riscv/kernel/cpufeature.o)
> > >>> referenced by errata.c:42 (arch/riscv/errata/thead/errata.c:42)
> > >>> arch/riscv/errata/thead/errata.o:(thead_feature_probe_func) in archive vmlinux.a
> > --
> > >> ld.lld: error: relocation R_RISCV_HI20 cannot be used against symbol 'riscv_cbom_block_size'; recompile with -fPIC
> > >>> defined in vmlinux.a(arch/riscv/mm/cacheflush.o)
> > >>> referenced by errata.c:42 (arch/riscv/errata/thead/errata.c:42)
> > >>> arch/riscv/errata/thead/errata.o:(thead_errata_patch_func) in archive vmlinux.a
> > --
> > >> ld.lld: error: relocation R_RISCV_LO12_S cannot be used against symbol 'riscv_cbom_block_size'; recompile with -fPIC
> > >>> defined in vmlinux.a(arch/riscv/mm/cacheflush.o)
> > >>> referenced by errata.c:42 (arch/riscv/errata/thead/errata.c:42)
> > >>> arch/riscv/errata/thead/errata.o:(thead_errata_patch_func) in archive vmlinux.a
> > --
> > >> ld.lld: error: relocation R_RISCV_HI20 cannot be used against symbol '__per_cpu_offset'; recompile with -fPIC
> > >>> defined in vmlinux.a(mm/percpu.o)
> > >>> referenced by errata.c:42 (arch/riscv/errata/thead/errata.c:42)
> > >>> arch/riscv/errata/thead/errata.o:(thead_feature_probe_func) in archive vmlinux.a
> > --
> > >> ld.lld: error: relocation R_RISCV_LO12_I cannot be used against symbol '__per_cpu_offset'; recompile with -fPIC
> > >>> defined in vmlinux.a(mm/percpu.o)
> > >>> referenced by errata.c:42 (arch/riscv/errata/thead/errata.c:42)
> > >>> arch/riscv/errata/thead/errata.o:(thead_feature_probe_func) in archive vmlinux.a
> >
>
> So I looked into those errors, the config is basically = RELOCATABLE +
> MEDLOW - EARLY_ALTERNATIVES. Then errata/thead is not compiled as

Thanks for taking a look. Shouldn't CONFIG_RELOCATABLE be setting
-fPIC? If so, why is LLD complaining about -fPIC not being used?

arch/riscv/Makefile sets -fPIE if CONFIG_RELOCATABLE == y.

Is it possible that -fpie was dropped for these object files, or
-fno-pic or -fno-pie was added to the cflags for these object files
somehow?

I've filed
https://github.com/ClangBuiltLinux/linux/issues/1872
to track this.

> medany, which makes sense since we only need this code to be medany
> when EARLY_ALTERNATIVES is enabled (because the code would be executed
> with mmu off, which is not the case here).
>
> I can fix those errors by adding the medany flag, but I'm not sure
> actually we want to do that since we do not need it and gcc does not
> complain: any idea?
>
> Alex
>
>
>
> > --
> > 0-DAY CI Kernel Test Service
> > https://github.com/intel/lkp-tests/wiki
>


--
Thanks,
~Nick Desaulniers

2023-06-19 21:40:08

by Palmer Dabbelt

[permalink] [raw]
Subject: Re: ld.lld: error: relocation R_RISCV_HI20 cannot be used against symbol 'misaligned_access_speed'; recompile with -fPIC

On Wed, 14 Jun 2023 09:40:28 PDT (-0700), [email protected] wrote:
> On Tue, Jun 13, 2023 at 4:17 AM Alexandre Ghiti <[email protected]> wrote:
>>
>> On Sun, Jun 11, 2023 at 2:11 AM kernel test robot <[email protected]> wrote:
>> >
>> > tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
>> > head: 022ce8862dff83c859089cd14bc4dca0733e2f90
>> > commit: 8dc2a7e8027fbeca0c7df81d4c82e735a59b5741 riscv: Fix relocatable kernels with early alternatives using -fno-pie
>> > date: 10 days ago
>> > config: riscv-randconfig-r022-20230611 (https://download.01.org/0day-ci/archive/20230611/[email protected]/config)
>> > compiler: clang version 16.0.4 (https://github.com/llvm/llvm-project.git ae42196bc493ffe877a7e3dff8be32035dea4d07)
>> > reproduce (this is a W=1 build):
>> > mkdir -p ~/bin
>> > wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
>> > chmod +x ~/bin/make.cross
>> > # install riscv cross compiling tool for clang build
>> > # apt-get install binutils-riscv64-linux-gnu
>> > # https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=8dc2a7e8027fbeca0c7df81d4c82e735a59b5741
>> > git remote add linus https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
>> > git fetch --no-tags linus master
>> > git checkout 8dc2a7e8027fbeca0c7df81d4c82e735a59b5741
>> > # save the config file
>> > mkdir build_dir && cp config build_dir/.config
>> > COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang ~/bin/make.cross W=1 O=build_dir ARCH=riscv olddefconfig
>> > COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang ~/bin/make.cross W=1 O=build_dir ARCH=riscv SHELL=/bin/bash
>> >
>> > If you fix the issue in a separate patch/commit (i.e. not just a new version of
>> > the same patch/commit), kindly add following tags
>> > | Reported-by: kernel test robot <[email protected]>
>> > | Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
>> >
>> > All errors (new ones prefixed by >>):
>> >
>> > >> ld.lld: error: relocation R_RISCV_HI20 cannot be used against symbol 'misaligned_access_speed'; recompile with -fPIC
>> > >>> defined in vmlinux.a(arch/riscv/kernel/cpufeature.o)
>> > >>> referenced by errata.c:42 (arch/riscv/errata/thead/errata.c:42)
>> > >>> arch/riscv/errata/thead/errata.o:(thead_feature_probe_func) in archive vmlinux.a
>> > --
>> > >> ld.lld: error: relocation R_RISCV_LO12_I cannot be used against symbol 'misaligned_access_speed'; recompile with -fPIC
>> > >>> defined in vmlinux.a(arch/riscv/kernel/cpufeature.o)
>> > >>> referenced by errata.c:42 (arch/riscv/errata/thead/errata.c:42)
>> > >>> arch/riscv/errata/thead/errata.o:(thead_feature_probe_func) in archive vmlinux.a
>> > --
>> > >> ld.lld: error: relocation R_RISCV_HI20 cannot be used against symbol 'riscv_cbom_block_size'; recompile with -fPIC
>> > >>> defined in vmlinux.a(arch/riscv/mm/cacheflush.o)
>> > >>> referenced by errata.c:42 (arch/riscv/errata/thead/errata.c:42)
>> > >>> arch/riscv/errata/thead/errata.o:(thead_errata_patch_func) in archive vmlinux.a
>> > --
>> > >> ld.lld: error: relocation R_RISCV_LO12_S cannot be used against symbol 'riscv_cbom_block_size'; recompile with -fPIC
>> > >>> defined in vmlinux.a(arch/riscv/mm/cacheflush.o)
>> > >>> referenced by errata.c:42 (arch/riscv/errata/thead/errata.c:42)
>> > >>> arch/riscv/errata/thead/errata.o:(thead_errata_patch_func) in archive vmlinux.a
>> > --
>> > >> ld.lld: error: relocation R_RISCV_HI20 cannot be used against symbol '__per_cpu_offset'; recompile with -fPIC
>> > >>> defined in vmlinux.a(mm/percpu.o)
>> > >>> referenced by errata.c:42 (arch/riscv/errata/thead/errata.c:42)
>> > >>> arch/riscv/errata/thead/errata.o:(thead_feature_probe_func) in archive vmlinux.a
>> > --
>> > >> ld.lld: error: relocation R_RISCV_LO12_I cannot be used against symbol '__per_cpu_offset'; recompile with -fPIC
>> > >>> defined in vmlinux.a(mm/percpu.o)
>> > >>> referenced by errata.c:42 (arch/riscv/errata/thead/errata.c:42)
>> > >>> arch/riscv/errata/thead/errata.o:(thead_feature_probe_func) in archive vmlinux.a
>> >
>>
>> So I looked into those errors, the config is basically = RELOCATABLE +
>> MEDLOW - EARLY_ALTERNATIVES. Then errata/thead is not compiled as
>
> Thanks for taking a look. Shouldn't CONFIG_RELOCATABLE be setting
> -fPIC? If so, why is LLD complaining about -fPIC not being used?
>
> arch/riscv/Makefile sets -fPIE if CONFIG_RELOCATABLE == y.
>
> Is it possible that -fpie was dropped for these object files, or
> -fno-pic or -fno-pie was added to the cflags for these object files
> somehow?
>
> I've filed
> https://github.com/ClangBuiltLinux/linux/issues/1872
> to track this.

Using R_RISCV_{HI20,LO12_I,LO12_S} to refer to non-absolute symbols in a
PIE shouldn't be allowed, it's not going to produce the right answer at
runtime.

We've got a lot of complicated bits in the build scripts so it's worth
checking to make sure that `-fPIE` actually manifests in the link step.
If it is and GNU LD isn't complaining then I think we've likely got a
linker bug.

>> medany, which makes sense since we only need this code to be medany
>> when EARLY_ALTERNATIVES is enabled (because the code would be executed
>> with mmu off, which is not the case here).
>>
>> I can fix those errors by adding the medany flag, but I'm not sure
>> actually we want to do that since we do not need it and gcc does not
>> complain: any idea?
>>
>> Alex
>>
>>
>>
>> > --
>> > 0-DAY CI Kernel Test Service
>> > https://github.com/intel/lkp-tests/wiki
>>
>
>
> --
> Thanks,
> ~Nick Desaulniers

2023-06-20 07:14:30

by Alexandre Ghiti

[permalink] [raw]
Subject: Re: ld.lld: error: relocation R_RISCV_HI20 cannot be used against symbol 'misaligned_access_speed'; recompile with -fPIC

On Wed, Jun 14, 2023 at 6:40 PM Nick Desaulniers
<[email protected]> wrote:
>
> On Tue, Jun 13, 2023 at 4:17 AM Alexandre Ghiti <[email protected]> wrote:
> >
> > On Sun, Jun 11, 2023 at 2:11 AM kernel test robot <[email protected]> wrote:
> > >
> > > tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
> > > head: 022ce8862dff83c859089cd14bc4dca0733e2f90
> > > commit: 8dc2a7e8027fbeca0c7df81d4c82e735a59b5741 riscv: Fix relocatable kernels with early alternatives using -fno-pie
> > > date: 10 days ago
> > > config: riscv-randconfig-r022-20230611 (https://download.01.org/0day-ci/archive/20230611/[email protected]/config)
> > > compiler: clang version 16.0.4 (https://github.com/llvm/llvm-project.git ae42196bc493ffe877a7e3dff8be32035dea4d07)
> > > reproduce (this is a W=1 build):
> > > mkdir -p ~/bin
> > > wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
> > > chmod +x ~/bin/make.cross
> > > # install riscv cross compiling tool for clang build
> > > # apt-get install binutils-riscv64-linux-gnu
> > > # https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=8dc2a7e8027fbeca0c7df81d4c82e735a59b5741
> > > git remote add linus https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
> > > git fetch --no-tags linus master
> > > git checkout 8dc2a7e8027fbeca0c7df81d4c82e735a59b5741
> > > # save the config file
> > > mkdir build_dir && cp config build_dir/.config
> > > COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang ~/bin/make.cross W=1 O=build_dir ARCH=riscv olddefconfig
> > > COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang ~/bin/make.cross W=1 O=build_dir ARCH=riscv SHELL=/bin/bash
> > >
> > > If you fix the issue in a separate patch/commit (i.e. not just a new version of
> > > the same patch/commit), kindly add following tags
> > > | Reported-by: kernel test robot <[email protected]>
> > > | Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
> > >
> > > All errors (new ones prefixed by >>):
> > >
> > > >> ld.lld: error: relocation R_RISCV_HI20 cannot be used against symbol 'misaligned_access_speed'; recompile with -fPIC
> > > >>> defined in vmlinux.a(arch/riscv/kernel/cpufeature.o)
> > > >>> referenced by errata.c:42 (arch/riscv/errata/thead/errata.c:42)
> > > >>> arch/riscv/errata/thead/errata.o:(thead_feature_probe_func) in archive vmlinux.a
> > > --
> > > >> ld.lld: error: relocation R_RISCV_LO12_I cannot be used against symbol 'misaligned_access_speed'; recompile with -fPIC
> > > >>> defined in vmlinux.a(arch/riscv/kernel/cpufeature.o)
> > > >>> referenced by errata.c:42 (arch/riscv/errata/thead/errata.c:42)
> > > >>> arch/riscv/errata/thead/errata.o:(thead_feature_probe_func) in archive vmlinux.a
> > > --
> > > >> ld.lld: error: relocation R_RISCV_HI20 cannot be used against symbol 'riscv_cbom_block_size'; recompile with -fPIC
> > > >>> defined in vmlinux.a(arch/riscv/mm/cacheflush.o)
> > > >>> referenced by errata.c:42 (arch/riscv/errata/thead/errata.c:42)
> > > >>> arch/riscv/errata/thead/errata.o:(thead_errata_patch_func) in archive vmlinux.a
> > > --
> > > >> ld.lld: error: relocation R_RISCV_LO12_S cannot be used against symbol 'riscv_cbom_block_size'; recompile with -fPIC
> > > >>> defined in vmlinux.a(arch/riscv/mm/cacheflush.o)
> > > >>> referenced by errata.c:42 (arch/riscv/errata/thead/errata.c:42)
> > > >>> arch/riscv/errata/thead/errata.o:(thead_errata_patch_func) in archive vmlinux.a
> > > --
> > > >> ld.lld: error: relocation R_RISCV_HI20 cannot be used against symbol '__per_cpu_offset'; recompile with -fPIC
> > > >>> defined in vmlinux.a(mm/percpu.o)
> > > >>> referenced by errata.c:42 (arch/riscv/errata/thead/errata.c:42)
> > > >>> arch/riscv/errata/thead/errata.o:(thead_feature_probe_func) in archive vmlinux.a
> > > --
> > > >> ld.lld: error: relocation R_RISCV_LO12_I cannot be used against symbol '__per_cpu_offset'; recompile with -fPIC
> > > >>> defined in vmlinux.a(mm/percpu.o)
> > > >>> referenced by errata.c:42 (arch/riscv/errata/thead/errata.c:42)
> > > >>> arch/riscv/errata/thead/errata.o:(thead_feature_probe_func) in archive vmlinux.a
> > >
> >
> > So I looked into those errors, the config is basically = RELOCATABLE +
> > MEDLOW - EARLY_ALTERNATIVES. Then errata/thead is not compiled as
>
> Thanks for taking a look. Shouldn't CONFIG_RELOCATABLE be setting
> -fPIC? If so, why is LLD complaining about -fPIC not being used?
>
> arch/riscv/Makefile sets -fPIE if CONFIG_RELOCATABLE == y.
>
> Is it possible that -fpie was dropped for these object files, or
> -fno-pic or -fno-pie was added to the cflags for these object files
> somehow?

There was a runtime issue where I had to drop the -fPIE for those
files because some part *may* be executed before the MMU is enabled,
so any access to a global symbol through the GOT needs a relocation
which is "done" only virtually.

commit 8dc2a7e8027f ("riscv: Fix relocatable kernels with early
alternatives using -fno-pie") added the -fno-pie flag, but not the
medany because the medany is correctly set in errata/thead/Makefile
only when EARLY_ALTERNATIVES is set.

So to me we do not need the medany flag if !EARLY_ALTERNATIVES since
the code is not executed with MMU off and then medlow should work.


>
> I've filed
> https://github.com/ClangBuiltLinux/linux/issues/1872
> to track this.
>
> > medany, which makes sense since we only need this code to be medany
> > when EARLY_ALTERNATIVES is enabled (because the code would be executed
> > with mmu off, which is not the case here).
> >
> > I can fix those errors by adding the medany flag, but I'm not sure
> > actually we want to do that since we do not need it and gcc does not
> > complain: any idea?
> >
> > Alex
> >
> >
> >
> > > --
> > > 0-DAY CI Kernel Test Service
> > > https://github.com/intel/lkp-tests/wiki
> >
>
>
> --
> Thanks,
> ~Nick Desaulniers