Closed d5bfafaa-05ff-4c34-845c-3d10c8ba0197 closed 6 years ago
Fix landed @ r342368
Thanks, I tested with that patch applied and it resolved the issue I had.
Should be fixed with https://reviews.llvm.org/D50965
Reduced testcase to show the issue.
$ cat t.c
extern void _local_bh_enable(void); extern void __local_bh_enable_ip(unsigned long ip, unsigned int cnt);
static inline attribute((always_inline, unused)) attribute((no_instrument_function)) void local_bh_enable(void) { local_bh_enable_ip(({ label here; here: (unsigned long)&&__here; }), (2 * (1UL << (0 + 8)))); } int irq_forced_thread_fn() { local_bh_enable(); return 0; } $ cat t.ksh clang -O2 -fno-PIE -c t.c -o clang.o "$@" objdump -dr clang.o |grep local_bh_enable_ip -B 6
$ ./t.ksh 54: 00 00 60 38 li r3,0 54: R_PPC64_ADDR16_LO .text+0x48 58: 00 02 80 38 li r4,512 5c: 00 00 63 3c addis r3,r3,0 5c: R_PPC64_ADDR16_HA .text+0x48 60: 01 00 00 48 bl 60 <local_bh_enable+0x20> 60: R_PPC64_REL24 __local_bh_enable_ip
$ ./t.ksh -fPIE 54: 00 00 62 3c addis r3,r2,0 54: R_PPC64_TOC16_HA .toc 58: 00 02 80 38 li r4,512 5c: 00 00 63 e8 ld r3,0(r3) 5c: R_PPC64_TOC16_LO_DS .toc 60: 01 00 00 48 bl 60 <local_bh_enable+0x20> 60: R_PPC64_REL24 __local_bh_enable_ip
Extended Description
I am attempting to build the powerpc Linux kernel (v4.19-rc2) with clang.
At link time, it will fail with a number of failed relocations:
ld: kernel/irq/manage.o: in function
local_bh_enable': manage.c:(.text+0x3ccc): relocation truncated to fit: R_PPC64_ADDR16_HA against
.text'+3cb80000000000003cb0:
3cb0: 00 00 4c 3c addis r2,r12,0
3cb4: 00 00 42 38 addi r2,r2,0
3cb8: a6 02 08 7c mflr r0
3cbc: 10 00 01 f8 std r0,16(r1)
3cc0: e1 ff 21 f8 stdu r1,-32(r1)
3cc4: 00 00 60 38 li r3,0
3cc8: 00 02 80 38 li r4,512
3ccc: 00 00 63 3c addis r3,r3,0
3cd0: 01 00 00 48 bl 3cd0 <local_bh_enable+0x20>
3cd4: 00 00 00 60 nop
3cd8: 20 00 21 38 addi r1,r1,32
3cdc: 10 00 01 e8 ld r0,16(r1)
3ce0: a6 03 08 7c mtlr r0
3ce4: 20 00 80 4e blr
It is suspected that the use of _THISIP is the cause of the error. On GCC this is placed in the TOC, but that is not the case for clang. I was able to reproduce with clang trunk.
I've attached the preprocessed source file. Here's the line used to compile it:
clang-7 -nostdinc -Qunused-arguments -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -fshort-wchar -Werror-implicit-function-declaration -Wno-format-security -std=gnu89 -no-integrated-as -fno-PIE -mlittle-endian -m64 -msoft-float -pipe -Iarch/powerpc -mabi=elfv2 -mcmodel=medium -mcpu=power8 -mtune=power9 -mno-altivec -mno-vsx -funit-at-a-time -fno-dwarf2-cfi-asm -Wa,-maltivec -Wa,-mpower8 -mlittle-endian -fno-delete-null-pointer-checks -Wno-duplicate-decl-specifier -O2 -Wframe-larger-than=2048 -fno-stack-protector -Wno-format-invalid-specifier -Wno-gnu -Wno-address-of-packed-member -Wno-tautological-compare -mno-global-merge -Wno-unused-const-variable -fomit-frame-pointer -g -fno-var-tracking -Wdeclaration-after-statement -Wno-pointer-sign -fno-strict-overflow -fno-merge-all-constants -fno-stack-check -Werror=implicit-int -Werror=strict-prototypes -Werror=date-time -Werror=incompatible-pointer-types -Wno-initializer-overrides -Wno-unused-value -Wno-format -Wno-sign-compare -Wno-format-zero-length -Wno-uninitialized -c -o manage.o manage.i
To reproduce from kernel sources:
Apply this patch: https://patchwork.ozlabs.org/patch/966825/
make ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- powernv_defconfig ./scripts/config -e PPC_DISABLE_WERROR ./scripts/config -d FTRACE ./scripts/config -d BTRFS_FS ./scripts/config -d MD_RAID456 make CC=clang-7 CLANG_TRIPLE=powerpc64le-linux-gnu \ ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu-
ld: kernel/irq/manage.o: in function
local_bh_enable': /scratch/joel/linus/./include/linux/bottom_half.h:32:(.text+0x3ccc): relocation truncated to fit: R_PPC64_ADDR16_HA against
.text'+3cb8 ld: kernel/rcu/srcutree.o: in functionlocal_bh_enable': /scratch/joel/linus/./include/linux/bottom_half.h:32:(.text+0x258c): relocation truncated to fit: R_PPC64_ADDR16_HA against
.text'+2578 ld: kernel/time/hrtimer.o: in functionlocal_bh_enable': /scratch/joel/linus/./include/linux/bottom_half.h:32:(.text+0x242c): relocation truncated to fit: R_PPC64_ADDR16_HA against
.text'+2418 ld: kernel/bpf/cpumap.o: in functionlocal_bh_enable': /scratch/joel/linus/./include/linux/bottom_half.h:32:(.text+0x134c): relocation truncated to fit: R_PPC64_ADDR16_HA against
.text'+1338 ld: drivers/net/ethernet/broadcom/tg3.o: in functionlocal_bh_enable': /scratch/joel/linus/./include/linux/bottom_half.h:32:(.text+0x87dc): relocation truncated to fit: R_PPC64_ADDR16_HA against
.text'+87c8 ld: drivers/net/ethernet/intel/e1000/e1000_main.o: in functionlocal_bh_enable': /scratch/joel/linus/./include/linux/bottom_half.h:32:(.text+0xc13c): relocation truncated to fit: R_PPC64_ADDR16_HA against
.text'+c128 ld: net/core/sock.o: in functionlocal_bh_enable': /scratch/joel/linus/./include/linux/bottom_half.h:32:(.text+0x5a6c): relocation truncated to fit: R_PPC64_ADDR16_HA against
.text'+5a58 ld: net/core/gen_estimator.o: in functionlocal_bh_enable': /scratch/joel/linus/./include/linux/bottom_half.h:32:(.text+0x2ec): relocation truncated to fit: R_PPC64_ADDR16_HA against
.text'+2d8 ld: net/core/dev.o: in functionlocal_bh_enable': /scratch/joel/linus/./include/linux/bottom_half.h:32:(.text+0x8a6c): relocation truncated to fit: R_PPC64_ADDR16_HA against
.text'+8a58 ld: net/core/neighbour.o: in functionlocal_bh_enable': /scratch/joel/linus/./include/linux/bottom_half.h:32:(.text+0x1f2c): relocation truncated to fit: R_PPC64_ADDR16_HA against
.text'+1f18 ld: net/sched/sch_generic.o: in function `local_bh_enable': /scratch/joel/linus/./include/linux/bottom_half.h:32:(.text+0x392c): additional relocation overflows omitted from the output