https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101726
Bug ID: 101726 Summary: target_clone resolver does not generate PIC despite -fPIC Product: gcc Version: 11.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: stefan.kneifel at bluewin dot ch Target Milestone: --- Created attachment 51243 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51243&action=edit Testcase: compile with -Os -fPIC When compiling code using target_clones with -fPIC, the automatically generated resolver refers to all the explicit targets correctly using R_X86_64_REX_GOTPCRELX, whereas it refers to the default target incorrectly using R_X86_64_PC32, resulting in an object file not linkable into a shared library. Compile the attached test.ii with: gcc -Os -pipe -fPIC -c test.ii and disassemble the output with: objdump -rd test.o -------------------------------------------- test.o: file format elf64-x86-64 Disassembly of section .text: 0000000000000000 <_Z3barv>: 0: e9 00 00 00 00 jmpq 5 <_Z3barv+0x5> 1: R_X86_64_PLT32 _Z3foov-0x4 Disassembly of section .text._Z3foov.resolver: 0000000000000000 <_Z3foov.resolver>: 0: 51 push %rcx 1: e8 00 00 00 00 callq 6 <_Z3foov.resolver+0x6> 2: R_X86_64_PLT32 __cpu_indicator_init-0x4 6: 48 8b 05 00 00 00 00 mov 0x0(%rip),%rax # d <_Z3foov.resolver+0xd> 9: R_X86_64_REX_GOTPCRELX __cpu_model-0x4 d: 8b 50 0c mov 0xc(%rax),%edx 10: 0f ba e2 0f bt $0xf,%edx 14: 73 09 jae 1f <_Z3foov.resolver+0x1f> 16: 48 8b 05 00 00 00 00 mov 0x0(%rip),%rax # 1d <_Z3foov.resolver+0x1d> 19: R_X86_64_REX_GOTPCRELX _Z3foov.avx512f.0-0x4 1d: eb 23 jmp 42 <_Z3foov.resolver+0x42> 1f: 0f ba e2 0a bt $0xa,%edx 23: 73 09 jae 2e <_Z3foov.resolver+0x2e> 25: 48 8b 05 00 00 00 00 mov 0x0(%rip),%rax # 2c <_Z3foov.resolver+0x2c> 28: R_X86_64_REX_GOTPCRELX _Z3foov.avx2.1-0x4 2c: eb 14 jmp 42 <_Z3foov.resolver+0x42> 2e: 0f ba e2 09 bt $0x9,%edx 32: 48 8d 05 00 00 00 00 lea 0x0(%rip),%rax # 39 <_Z3foov.resolver+0x39> 35: R_X86_64_PC32 _Z3foov.default.3-0x4 39: 73 07 jae 42 <_Z3foov.resolver+0x42> 3b: 48 8b 05 00 00 00 00 mov 0x0(%rip),%rax # 42 <_Z3foov.resolver+0x42> 3e: R_X86_64_REX_GOTPCRELX _Z3foov.avx.2-0x4 42: 5a pop %rdx 43: c3 retq -------------------------------------------- This should be consistent, and _Z3foov.default.3 should also be read from the GOT.