Bug 28370

Summary: aarch64: relocation R_AARCH64_ADR_PREL_PG_HI21 against STT_GNU_IFUNC symbol `ifunc' isn't handled by elf64_aarch64_final_link_relocate
Product: binutils Reporter: Fangrui Song <i>
Component: ldAssignee: Not yet assigned to anyone <unassigned>
Status: UNCONFIRMED ---    
Severity: normal    
Priority: P2    
Version: unspecified   
Target Milestone: ---   
Host: Target: aarch64-*
Build: Last reconfirmed:

Description Fangrui Song 2021-09-22 03:35:13 UTC
GCC -fpic may generate direct relocations to take the address of an ifunc,
since an ifunc is not required to use the function attribute.
(GCC appears to use GOT when taking the address of an hidden __attribute__((ifunc(...))))

cat > ./a.c <<eof
__attribute__((visibility("hidden"))) void ifunc(void);
void (*addr(void))(void) { return ifunc; }
eof
cat > ./b.c <<eof
void impl(void) {}
void *resolver() { return impl; }
__attribute__((ifunc("resolver"), visibility("hidden"))) void ifunc(void);
eof

aarch64-linux-gnu-gcc -fpic -c a.c b.c

% ./ld-new -shared a.o b.o                                
./ld-new: a.o: relocation R_AARCH64_ADR_PREL_PG_HI21 against STT_GNU_IFUNC symbol `ifunc' isn't handled by elf64_aarch64_final_link_relocate
a.o: in function `addr':
a.c:(.text+0x0): dangerous relocation: unsupported relocation
./ld-new: a.o: relocation R_AARCH64_ADD_ABS_LO12_NC against STT_GNU_IFUNC symbol `ifunc' isn't handled by elf64_aarch64_final_link_relocate
a.c:(.text+0x4): dangerous relocation: unsupported relocation


The x86-64 port handles the case.