diff options
author | H.J. Lu <hjl.tools@gmail.com> | 2021-06-17 14:11:28 -0700 |
---|---|---|
committer | H.J. Lu <hjl.tools@gmail.com> | 2021-07-08 18:14:31 -0700 |
commit | 6f365fda85a2e2682b197540d14adf66c4261b19 (patch) | |
tree | f746621b46e022fabe3662b04da4d5c2a36f2e1b /ld/testsuite/ld-elf | |
parent | 6320fd00dc374f74658c7e4b7dffbe1d71723284 (diff) | |
download | gdb-6f365fda85a2e2682b197540d14adf66c4261b19.zip gdb-6f365fda85a2e2682b197540d14adf66c4261b19.tar.gz gdb-6f365fda85a2e2682b197540d14adf66c4261b19.tar.bz2 |
elf: Add GNU_PROPERTY_1_NEEDED check
If GNU_PROPERTY_1_NEEDED_INDIRECT_EXTERN_ACCESS is set on any input
relocatable files:
1. Don't generate copy relocations.
2. Turn off extern_protected_data since it implies
GNU_PROPERTY_NO_COPY_ON_PROTECTED.
3. Treate reference to protected symbols with indirect external access
as local.
4. Set GNU_PROPERTY_1_NEEDED_INDIRECT_EXTERN_ACCESS on output.
5. When generating executable, clear this bit when there are non-GOT or
non-PLT relocations in input relocatable files without the bit set.
6. Add -z [no]indirect-extern-access to control indirect external access.
bfd/
* elf-bfd (elf_obj_tdata): Add has_indirect_extern_access.
(elf_has_indirect_extern_access): New.
* elf-properties.c (_bfd_elf_parse_gnu_properties): Set
elf_has_indirect_extern_access and elf_has_no_copy_on_protected
when seeing GNU_PROPERTY_1_NEEDED_INDIRECT_EXTERN_ACCESS.
(elf_write_gnu_propertie): Add an argument to pass link_info.
Set needed_1_p for GNU_PROPERTY_1_NEEDED in memory.
(_bfd_elf_link_setup_gnu_properties): Handle
GNU_PROPERTY_1_NEEDED_INDIRECT_EXTERN_ACCESS for
-z indirect-extern-access. Set nocopyreloc to true and
extern_protected_data to false for indirect external access.
(_bfd_elf_convert_gnu_properties): Updated.
* elf32-i386.c (elf_i386_check_relocs): Set
non_got_ref_without_indirect_extern_access on legacy non-GOT or
non-PLT references.
* elf64-x86-64.c (elf_x86_64_check_relocs): Likewise.
* elflink.c (_bfd_elf_symbol_refs_local_p): Return true for
STV_PROTECTED symbols with indirect external access.
* elfxx-x86.c (_bfd_x86_elf_adjust_dynamic_symbol): Clear
indirect_extern_access for legacy non-GOT/non-PLT references.
* elfxx-x86.h (elf_x86_link_hash_entry): Add
non_got_ref_without_indirect_extern_access.
include/
* bfdlink.h (bfd_link_info): Add indirect_extern_access and
needed_1_p. Change nocopyreloc to int.
ld/
* NEWS: Mention -z [no]indirect-extern-access
* ld.texi: Document -z [no]indirect-extern-access
* ldmain.c (main): Initialize link_info.indirect_extern_access
to -1.
* emulparams/extern_protected_data.sh: Support
-z [no]indirect-extern-access.
* testsuite/ld-elf/indirect-extern-access-1.rd: New file
* testsuite/ld-elf/indirect-extern-access-1a.c: Likewise.
* testsuite/ld-elf/indirect-extern-access-1b.c: Likewise.
* testsuite/ld-elf/indirect-extern-access-2.rd: Likewise.
* testsuite/ld-elf/indirect-extern-access-2a.c: Likewise.
* testsuite/ld-elf/indirect-extern-access-2b.c: Likewise.
* testsuite/ld-elf/indirect-extern-access-3.rd: Likewise.
* testsuite/ld-elf/indirect-extern-access.S: Likewise.
* testsuite/ld-elf/property-1_needed-1b.d: Likewise.
* testsuite/ld-elf/property-1_needed-1c.d: Likewise.
* testsuite/ld-x86-64/indirect-extern-access.rd: Likewise.
* testsuite/ld-x86-64/protected-data-1.h: Likewise.
* testsuite/ld-x86-64/protected-data-1a.c: Likewise.
* testsuite/ld-x86-64/protected-data-1b.c: Likewise.
* testsuite/ld-x86-64/protected-data-2a.S: Likewise.
* testsuite/ld-x86-64/protected-data-2b.S: Likewise.
* testsuite/ld-x86-64/protected-func-2a.S: Likewise.
* testsuite/ld-x86-64/protected-func-2b.S: Likewise.
* testsuite/ld-x86-64/protected-func-2c.c: Likewise.
* testsuite/ld-elf/linux-x86.exp: Run test with
GNU_PROPERTY_1_NEEDED_INDIRECT_EXTERN_ACCESS.
* testsuite/ld-x86-64/x86-64.exp: Run tests for protected
function and data with indirect external access.
Diffstat (limited to 'ld/testsuite/ld-elf')
-rw-r--r-- | ld/testsuite/ld-elf/indirect-extern-access-1.rd | 8 | ||||
-rw-r--r-- | ld/testsuite/ld-elf/indirect-extern-access-1a.c | 1 | ||||
-rw-r--r-- | ld/testsuite/ld-elf/indirect-extern-access-1b.c | 12 | ||||
-rw-r--r-- | ld/testsuite/ld-elf/indirect-extern-access-2.rd | 8 | ||||
-rw-r--r-- | ld/testsuite/ld-elf/indirect-extern-access-2a.c | 10 | ||||
-rw-r--r-- | ld/testsuite/ld-elf/indirect-extern-access-2b.c | 13 | ||||
-rw-r--r-- | ld/testsuite/ld-elf/indirect-extern-access-3.rd | 8 | ||||
-rw-r--r-- | ld/testsuite/ld-elf/indirect-extern-access.S | 20 | ||||
-rw-r--r-- | ld/testsuite/ld-elf/linux-x86.exp | 97 | ||||
-rw-r--r-- | ld/testsuite/ld-elf/property-1_needed-1b.d | 16 | ||||
-rw-r--r-- | ld/testsuite/ld-elf/property-1_needed-1c.d | 17 |
11 files changed, 210 insertions, 0 deletions
diff --git a/ld/testsuite/ld-elf/indirect-extern-access-1.rd b/ld/testsuite/ld-elf/indirect-extern-access-1.rd new file mode 100644 index 0000000..39dc89a --- /dev/null +++ b/ld/testsuite/ld-elf/indirect-extern-access-1.rd @@ -0,0 +1,8 @@ +#... +[a-f0-9]+ +[0-9a-f]+ +R_.*_COPY +[a-f0-9]+ +indirect_extern_access( \+ 0|) +#... +Displaying notes found in: .note.gnu.property +[ ]+Owner[ ]+Data size[ ]+Description + GNU 0x[0-9a-f]+ NT_GNU_PROPERTY_TYPE_0 + Properties: 1_needed: +#pass diff --git a/ld/testsuite/ld-elf/indirect-extern-access-1a.c b/ld/testsuite/ld-elf/indirect-extern-access-1a.c new file mode 100644 index 0000000..4789810 --- /dev/null +++ b/ld/testsuite/ld-elf/indirect-extern-access-1a.c @@ -0,0 +1 @@ +int indirect_extern_access = 1; diff --git a/ld/testsuite/ld-elf/indirect-extern-access-1b.c b/ld/testsuite/ld-elf/indirect-extern-access-1b.c new file mode 100644 index 0000000..68adae5 --- /dev/null +++ b/ld/testsuite/ld-elf/indirect-extern-access-1b.c @@ -0,0 +1,12 @@ +#include <stdio.h> + +extern int indirect_extern_access; + +int +main (void) +{ + if (indirect_extern_access == 1) + puts ("PASS"); + + return 0; +} diff --git a/ld/testsuite/ld-elf/indirect-extern-access-2.rd b/ld/testsuite/ld-elf/indirect-extern-access-2.rd new file mode 100644 index 0000000..9c7d72f --- /dev/null +++ b/ld/testsuite/ld-elf/indirect-extern-access-2.rd @@ -0,0 +1,8 @@ +#... +[a-f0-9]+ +[0-9a-f]+ +R_.*_JUMP_SLO(T|) +[a-f0-9]+ +indirect_extern_access( \+ 0|) +#... +Displaying notes found in: .note.gnu.property +[ ]+Owner[ ]+Data size[ ]+Description + GNU 0x[0-9a-f]+ NT_GNU_PROPERTY_TYPE_0 + Properties: 1_needed: +#pass diff --git a/ld/testsuite/ld-elf/indirect-extern-access-2a.c b/ld/testsuite/ld-elf/indirect-extern-access-2a.c new file mode 100644 index 0000000..cb57068 --- /dev/null +++ b/ld/testsuite/ld-elf/indirect-extern-access-2a.c @@ -0,0 +1,10 @@ +void +indirect_extern_access (void) +{ +} + +void * +indirect_extern_access_p (void) +{ + return indirect_extern_access; +} diff --git a/ld/testsuite/ld-elf/indirect-extern-access-2b.c b/ld/testsuite/ld-elf/indirect-extern-access-2b.c new file mode 100644 index 0000000..dedfd9b --- /dev/null +++ b/ld/testsuite/ld-elf/indirect-extern-access-2b.c @@ -0,0 +1,13 @@ +#include <stdio.h> + +extern void indirect_extern_access (void); +extern void *indirect_extern_access_p (void); + +int +main (void) +{ + if (&indirect_extern_access == indirect_extern_access_p ()) + puts ("PASS"); + + return 0; +} diff --git a/ld/testsuite/ld-elf/indirect-extern-access-3.rd b/ld/testsuite/ld-elf/indirect-extern-access-3.rd new file mode 100644 index 0000000..ce777a5 --- /dev/null +++ b/ld/testsuite/ld-elf/indirect-extern-access-3.rd @@ -0,0 +1,8 @@ +#... +[a-f0-9]+ +[0-9a-f]+ +R_.*_GLOB_DAT +[a-f0-9]+ +indirect_extern_access( \+ 0|) +#... +Displaying notes found in: .note.gnu.property +[ ]+Owner[ ]+Data size[ ]+Description + GNU 0x[0-9a-f]+ NT_GNU_PROPERTY_TYPE_0 + Properties: 1_needed: indirect external access +#pass diff --git a/ld/testsuite/ld-elf/indirect-extern-access.S b/ld/testsuite/ld-elf/indirect-extern-access.S new file mode 100644 index 0000000..25b88ba --- /dev/null +++ b/ld/testsuite/ld-elf/indirect-extern-access.S @@ -0,0 +1,20 @@ +# ifdef __LP64__ +# define ALIGN 3 +# else +# define ALIGN 2 +# endif + .section ".note.gnu.property", "a" + .p2align ALIGN + .long 1f - 0f /* name length */ + .long 5f - 2f /* data length */ + .long 5 /* note type */ +0: .asciz "GNU" /* vendor name */ +1: + .p2align ALIGN +2: .long 0xb0008000 /* pr_type. */ + .long 4f - 3f /* pr_datasz. */ +3: + .long 0x1 +4: + .p2align ALIGN +5: diff --git a/ld/testsuite/ld-elf/linux-x86.exp b/ld/testsuite/ld-elf/linux-x86.exp index 7e3a0b7..8192374 100644 --- a/ld/testsuite/ld-elf/linux-x86.exp +++ b/ld/testsuite/ld-elf/linux-x86.exp @@ -73,6 +73,103 @@ run_ld_link_tests [list \ ] \ ] +run_cc_link_tests [list \ + [list \ + "Build indirect-extern-access-1.so" \ + "-shared" \ + "-fPIC" \ + { indirect-extern-access-1a.c } \ + {} \ + "indirect-extern-access-1.so" \ + ] \ + [list \ + "Build indirect-extern-access-1a without PIE" \ + "$NOPIE_LDFLAGS -Wl,--no-as-needed \ + tmpdir/indirect-extern-access-1.so" \ + "$NOPIE_CFLAGS" \ + { indirect-extern-access.S indirect-extern-access-1b.c } \ + {{readelf -rn indirect-extern-access-1.rd}} \ + "indirect-extern-access-1a" \ + ] \ + [list \ + "Build indirect-extern-access-2.so" \ + "-shared" \ + "-fPIC" \ + { indirect-extern-access-2a.c } \ + {} \ + "indirect-extern-access-2.so" \ + ] \ + [list \ + "Build indirect-extern-access-2a without PIE" \ + "$NOPIE_LDFLAGS -Wl,--no-as-needed \ + tmpdir/indirect-extern-access-2.so" \ + "$NOPIE_CFLAGS" \ + { indirect-extern-access.S indirect-extern-access-1b.c } \ + {{readelf -rn indirect-extern-access-2.rd}} \ + "indirect-extern-access-2a" \ + ] \ + [list \ + "Build indirect-extern-access-2b with PIE" \ + "-pie -Wl,--no-as-needed \ + tmpdir/indirect-extern-access-2.so" \ + "-fpie" \ + { indirect-extern-access.S indirect-extern-access-2b.c } \ + {{readelf -rn indirect-extern-access-3.rd}} \ + "indirect-extern-access-2b" \ + ] \ +] + +run_ld_link_exec_tests [list \ + [list \ + "Run indirect-extern-access-1a without PIE" \ + "$NOPIE_LDFLAGS" \ + "" \ + { indirect-extern-access.S indirect-extern-access-1b.c } \ + "indirect-extern-access-1a" \ + "pass.out" \ + "$NOPIE_CFLAGS" \ + "" \ + "" \ + "tmpdir/indirect-extern-access-1.so" \ + ] \ + [list \ + "Run indirect-extern-access-1b with PIE" \ + "-pie" \ + "" \ + { indirect-extern-access.S indirect-extern-access-1b.c } \ + "indirect-extern-access-1b" \ + "pass.out" \ + "-fpie" \ + "" \ + "" \ + "tmpdir/indirect-extern-access-1.so" \ + ] \ + [list \ + "Run indirect-extern-access-2a without PIE" \ + "$NOPIE_LDFLAGS" \ + "" \ + { indirect-extern-access.S indirect-extern-access-2b.c } \ + "indirect-extern-access-2a" \ + "pass.out" \ + "$NOPIE_CFLAGS" \ + "" \ + "" \ + "tmpdir/indirect-extern-access-2.so" \ + ] \ + [list \ + "Run indirect-extern-access-2b with PIE" \ + "-pie" \ + "" \ + { indirect-extern-access.S indirect-extern-access-2b.c } \ + "indirect-extern-access-2b" \ + "pass.out" \ + "-fpie" \ + "" \ + "" \ + "tmpdir/indirect-extern-access-2.so" \ + ] \ +] + proc elfedit_test { options test output } { global ELFEDIT global READELF diff --git a/ld/testsuite/ld-elf/property-1_needed-1b.d b/ld/testsuite/ld-elf/property-1_needed-1b.d new file mode 100644 index 0000000..b7a9eea --- /dev/null +++ b/ld/testsuite/ld-elf/property-1_needed-1b.d @@ -0,0 +1,16 @@ +#source: empty.s +#as: +#ld: -shared -z indirect-extern-access +#readelf: -n +#xfail: ![check_shared_lib_support] +#notarget: am33_2.0-*-* hppa*-*-hpux* mn10300-*-* +# Assembly source file for the HPPA assembler is renamed and modifed by +# sed. mn10300 has relocations in .note.gnu.property section which +# elf_parse_notes doesn't support. + +#... +Displaying notes found in: .note.gnu.property +[ ]+Owner[ ]+Data size[ ]+Description + GNU 0x[0-9a-f]+ NT_GNU_PROPERTY_TYPE_0 + Properties: 1_needed: indirect external access +#pass diff --git a/ld/testsuite/ld-elf/property-1_needed-1c.d b/ld/testsuite/ld-elf/property-1_needed-1c.d new file mode 100644 index 0000000..21e1d26 --- /dev/null +++ b/ld/testsuite/ld-elf/property-1_needed-1c.d @@ -0,0 +1,17 @@ +#source: empty.s +#source: property-1_needed-1.s +#as: +#ld: -shared -z noindirect-extern-access +#readelf: -n +#xfail: ![check_shared_lib_support] +#notarget: am33_2.0-*-* hppa*-*-hpux* mn10300-*-* +# Assembly source file for the HPPA assembler is renamed and modifed by +# sed. mn10300 has relocations in .note.gnu.property section which +# elf_parse_notes doesn't support. + +#... +Displaying notes found in: .note.gnu.property +[ ]+Owner[ ]+Data size[ ]+Description + GNU 0x[0-9a-f]+ NT_GNU_PROPERTY_TYPE_0 + Properties: 1_needed: <unknown: 2> +#pass |