Bug 28672 - Link failure on some targets when building as PIE
Summary: Link failure on some targets when building as PIE
Status: RESOLVED NOTABUG
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.37
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-12-08 03:43 UTC by Siddhesh Poyarekar
Modified: 2024-02-15 06:08 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Siddhesh Poyarekar 2021-12-08 03:43:32 UTC
When building binaries in glibc as PIE, the linker fails on multiple architectures when handling relative relocations.  This one is for ia64:

ia64-glibc-linux-gnu-gcc -o build-many-3/build/glibcs/ia64-linux-gnu/glibc/support/test-run-command -nostdlib -nostartfiles -static     build-many-3/build/glibcs/ia64-linux-gnu/glibc/csu/crt1.o build-many-3/build/glibcs/ia64-linux-gnu/glibc/csu/crti.o `ia64-glibc-linux-gnu-gcc  --print-file-name=crtbegin.o` build-many-3/build/glibcs/ia64-linux-gnu/glibc/support/test-run-command.o build-many-3/build/glibcs/ia64-linux-gnu/glibc/elf/static-stubs.o build-many-3/build/glibcs/ia64-linux-gnu/glibc/support/libsupport_nonshared.a  -Wl,--start-group build-many-3/build/glibcs/ia64-linux-gnu/glibc/libc.a -lgcc  -Wl,--end-group `ia64-glibc-linux-gnu-gcc  --print-file-name=crtend.o` build-many-3/build/glibcs/ia64-linux-gnu/glibc/csu/crtn.o
build-many-3/build/glibcs/ia64-linux-gnu/glibc/libc.a(dl-support.o): in function `_dl_aux_init':
build-many-3/src/glibc/elf/dl-support.c:254:(.text+0x42): relocation truncated to fit: GPREL22 against `.text'
build-many-3/build/glibcs/ia64-linux-gnu/glibc/libc.a(dl-support.o): in function `setup_vdso':
build-many-3/src/glibc/elf/setup-vdso.h:108:(.text+0x1092): relocation truncated to fit: GPREL22 against `.text'
collect2: error: ld returned 1 exit status
make[3]: *** [../Rules:269: build-many-3/build/glibcs/ia64-linux-gnu/glibc/support/test-run-command] Error 1

I'll post a more reduced reproducer soon, this is from build-many-glibcs.py; I need the bug number as a reference to record in glibc as I enable PIE by default there.

Affected targets:

hppa-linux-gnu
ia64-linux-gnu
csky-linux-gnuabiv2
alpha-linux-gnu
Comment 1 Alan Modra 2021-12-11 01:05:39 UTC
Since you are building -static the executable may be pulling in most of libc.a and thus be quite large.  A relocation overflow is very likely the correct result from the linker.  You might need to explore gcc options for compiling in larger code models.
Comment 2 Alan Modra 2024-02-15 06:08:07 UTC
Closing, assuming comment #1 was true given there was no reply.