Page MenuHomeFreeBSD

Handle non-plt IRELATIVE relocations.
ClosedPublic

Authored by kib on Wed, Feb 12, 5:50 PM.

Details

Summary

amd64 only ATM, will add i386 if this works.

Diff Detail

Repository
rS FreeBSD src repository
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

kib created this revision.Wed, Feb 12, 5:50 PM

Overall seems reasonable

libexec/rtld-elf/amd64/reloc.c
306 ↗(On Diff #68211)

tiny nit, extra space here compared to others

kib marked an inline comment as done.Wed, Feb 12, 10:10 PM

fwiw I believe obj->gnu_ifunc is a vestigial bit of an earlier attempt to do non-plt ifuncs that got killed off in rS343484 and is the same as you are doing now (i.e. non-plt ifuncs)

actually I'm wrong.. I was confusing gnu ifuncs and non-plt gnu ifuncs, it was only the non-plt ones that got nerfed in rS341441 and rS343484.

Is there any case where IRELATIVE is used outside of GNU IFUNC btw?

Also, is there a fresher description of any of this than the old ifunc.txt file from https://sites.google.com/site/x32abi/documents ?

(A blatant error in that document is that it defines that the resolver takes no parameters. Given the resolver is called before the PLT is up and running, this is stupid, because on non x86* cpus, the cpu model information is coming from the auxv and is not directly available through an unprivileged instruction, so the workaround on x86* of __builtin_cpu_supports() calls is nonsensical. FreeBSD ifuncs always pass the available cpu feature flags in as parameters to the resolver, even on x86* where you can theoretically get it from a compiler builtin)

dim accepted this revision.Thu, Feb 13, 12:38 AM

This appears to work OK for libc.so.7 linked with lld 10.0.0, e.g. with IRELATIVE relocations in the .rela.dyn section. I copied the resulting ld-elf.so.1 to /libexec, and the newly linked libc.so.7 to /lib, and I haven't found anything yet which doesn't run. :)

This revision is now accepted and ready to land.Thu, Feb 13, 12:38 AM
kib updated this revision to Diff 68242.Thu, Feb 13, 11:12 AM

Add other arches.
It might be that powerpc/powerpc64 already handle that.

Nothing tested.

This revision now requires review to proceed.Thu, Feb 13, 11:12 AM
kib added a comment.Thu, Feb 13, 11:16 AM

Also, is there a fresher description of any of this than the old ifunc.txt file from https://sites.google.com/site/x32abi/documents ?

I am not sure, the descriptions of IRELATIVE and GNU_IFUNC are embedded into psABI docs for x86 now.

dim added a comment.Thu, Feb 13, 11:38 AM

I seem to get compilation errors with the latest version of this:

/usr/src/libexec/rtld-elf/i386/reloc.c:266:8: error: use of undeclared identifier 'R_I386_IRELATIVE'
                case R_I386_IRELATIVE:
                     ^
/usr/src/libexec/rtld-elf/i386/reloc.c:396:28: error: incompatible pointer types passing 'const Elf_Rel
*' (aka 'const Elf32_Rel *') to parameter of type 'const Elf_Rela *' (aka 'const Elf32_Rela *') [-Werror
,-Wincompatible-pointer-types]
--- all_subdir_bin ---
--- all_subdir_bin/pwd ---
===> bin/pwd (all)
--- all_subdir_libexec ---
                        reloc_iresolve_one(obj, rel, lockstate);
                                                ^~~
/usr/src/libexec/rtld-elf/i386/reloc.c:372:52: note: passing argument to parameter 'rel' here
reloc_iresolve_one(Obj_Entry *obj, const Elf_Rela *rel,
                                                   ^
/usr/src/libexec/rtld-elf/i386/reloc.c:412:34: error: use of undeclared identifier 'R_I386_IRELATIVE'
                if (ELF_R_TYPE(rel->r_info) == R_I386_IRELATIVE)
                                               ^
/usr/src/libexec/rtld-elf/i386/reloc.c:413:28: error: incompatible pointer types passing 'const Elf_Rel
*' (aka 'const Elf32_Rel *') to parameter of type 'const Elf_Rela *' (aka 'const Elf32_Rela *') [-Werror
,-Wincompatible-pointer-types]
                        reloc_iresolve_one(obj, rel, lockstate);
                                                ^~~
/usr/src/libexec/rtld-elf/i386/reloc.c:372:52: note: passing argument to parameter 'rel' here
reloc_iresolve_one(Obj_Entry *obj, const Elf_Rela *rel,
                                                   ^
4 errors generated.
*** [reloc.o] Error code 1
dim added a comment.Thu, Feb 13, 11:41 AM

It looks like s/R_I386_IRELATIVE/R_386_IRELATIVE/g should help. Not sure why the naming of the macro is inconsistent, probably a historic thing.

kib updated this revision to Diff 68262.Thu, Feb 13, 6:20 PM

This variant passed tinderbox.

This revision was not accepted when it landed; it landed in state Needs Review.Thu, Feb 13, 11:42 PM
This revision was automatically updated to reflect the committed changes.