]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
x86: Make protected symbols local for -shared
authorFangrui Song <i@maskray.me>
Sat, 25 Jun 2022 17:44:26 +0000 (10:44 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Mon, 25 Jul 2022 17:01:37 +0000 (10:01 -0700)
commit366e8fc8f7b269f4c68d0d5768c64a5a7ca42d6b
tree963d1b04d8125817089cd8e34c0809ed80b5141c
parent97acb51d6ac5b3e09b5817edc7a41678d96e945c
x86: Make protected symbols local for -shared

Call _bfd_elf_symbol_refs_local_p with local_protected==true.  This has
2 noticeable effects for -shared:

* GOT-generating relocations referencing a protected data symbol no
  longer lead to a GLOB_DAT (similar to a hidden symbol).
* Direct access relocations (e.g. R_X86_64_PC32) no longer has the
  confusing diagnostic below.

    __attribute__((visibility("protected"))) void *foo() {
      return (void *)foo;
    }

    // gcc -fpic -shared -fuse-ld=bfd
    relocation R_X86_64_PC32 against protected symbol `foo' can not be used when making a shared object

The new behavior matches arm, aarch64 (commit
83c325007c5599fa9b60b8d5f7b84842160e1d1b), and powerpc ports, and other
linkers: gold and ld.lld.

Note: if some code tries to use direct access relocations to take the
address of foo, the pointer equality will break, but the error should be
reported on the executable link, not on the innocent shared object link.
glibc 2.36 will give a warning at relocation resolving time.

With this change, `#define elf_backend_extern_protected_data 1` is no
longer effective.  Just remove it.

Remove the test "Run protected-func-1 without PIE" since -fno-pic
address taken operation in the executable doesn't work with protected
symbol in a shared object by default.  Similarly, remove
protected-data-1a and protected-data-1b.  protected-data-1b can be made
working by removing HAVE_LD_PIE_COPYRELOC from GCC
(https://sourceware.org/pipermail/gcc-patches/2022-June/596678.html).

(cherry picked from commit d19a265487eda186b6977d9d15648cda9fad3298)
13 files changed:
bfd/elf32-i386.c
bfd/elf64-x86-64.c
bfd/elfxx-x86.c
ld/testsuite/ld-i386/protected1.d
ld/testsuite/ld-i386/protected3.d
ld/testsuite/ld-i386/protected6a.d
ld/testsuite/ld-x86-64/pr24151a-x32.d
ld/testsuite/ld-x86-64/pr24151a.d
ld/testsuite/ld-x86-64/protected1.d
ld/testsuite/ld-x86-64/protected3.d
ld/testsuite/ld-x86-64/protected6a.d
ld/testsuite/ld-x86-64/protected7a.d
ld/testsuite/ld-x86-64/x86-64.exp