diff options
Diffstat (limited to 'ld')
-rw-r--r-- | ld/ChangeLog | 15 | ||||
-rw-r--r-- | ld/NEWS | 2 | ||||
-rw-r--r-- | ld/emultempl/elf32.em | 46 | ||||
-rw-r--r-- | ld/testsuite/ld-elf/elf.exp | 21 | ||||
-rw-r--r-- | ld/testsuite/ld-elf/mbind1.s | 43 | ||||
-rw-r--r-- | ld/testsuite/ld-elf/mbind1a.d | 44 | ||||
-rw-r--r-- | ld/testsuite/ld-elf/mbind1b.d | 44 | ||||
-rw-r--r-- | ld/testsuite/ld-elf/mbind1c.d | 44 | ||||
-rw-r--r-- | ld/testsuite/ld-elf/mbind2a.s | 15 | ||||
-rw-r--r-- | ld/testsuite/ld-elf/mbind2b.c | 17 |
10 files changed, 290 insertions, 1 deletions
diff --git a/ld/ChangeLog b/ld/ChangeLog index c3490a5..c9298e9 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,18 @@ +2017-04-04 H.J. Lu <hongjiu.lu@intel.com> + + * NEWS: Mention support for ELF SHF_GNU_MBIND and + PT_GNU_MBIND_XXX. + * emultempl/elf32.em (gld${EMULATION_NAME}_place_orphan): Place + input GNU_MBIND sections with the same type, attributes and + sh_info field into a single output GNU_MBIND section. + * testsuite/ld-elf/elf.exp: Run mbind2a and mbind2b. + * testsuite/ld-elf/mbind1.s: New file. + * testsuite/ld-elf/mbind1a.d: Likewise. + * testsuite/ld-elf/mbind1b.d: Likewise. + * testsuite/ld-elf/mbind1c.d: Likewise. + * testsuite/ld-elf/mbind2a.s: Likewise. + * testsuite/ld-elf/mbind2b.c: Likewise. + 2017-04-03 H.J. Lu <hongjiu.lu@intel.com> * NEWS: Mention support for ELF GNU program properties. @@ -1,5 +1,7 @@ -*- text -*- +* Add support for ELF SHF_GNU_MBIND and PT_GNU_MBIND_XXX. + * Add support for ELF GNU program properties. * Add support for the Texas Instruments PRU processor. diff --git a/ld/emultempl/elf32.em b/ld/emultempl/elf32.em index 007e48d..3442c95 100644 --- a/ld/emultempl/elf32.em +++ b/ld/emultempl/elf32.em @@ -2093,6 +2093,47 @@ gld${EMULATION_NAME}_place_orphan (asection *s, } } + if (!bfd_link_relocatable (&link_info) + && (s->flags & SEC_ALLOC) != 0 + && (elf_section_flags (s) & SHF_GNU_MBIND) != 0) + { + /* Find the output mbind section with the same type, attributes + and sh_info field. */ + for (os = &lang_output_section_statement.head->output_section_statement; + os != NULL; + os = os->next) + if (os->bfd_section != NULL + && !bfd_is_abs_section (os->bfd_section) + && (elf_section_flags (os->bfd_section) & SHF_GNU_MBIND) != 0 + && ((s->flags & (SEC_ALLOC + | SEC_LOAD + | SEC_HAS_CONTENTS + | SEC_READONLY + | SEC_CODE)) + == (os->bfd_section->flags & (SEC_ALLOC + | SEC_LOAD + | SEC_HAS_CONTENTS + | SEC_READONLY + | SEC_CODE))) + && (elf_section_data (os->bfd_section)->this_hdr.sh_info + == elf_section_data (s)->this_hdr.sh_info)) + { + lang_add_section (&os->children, s, NULL, os); + return os; + } + + /* Create the output mbind section with the ".mbind." prefix + in section name. */ + if ((s->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0) + secname = ".mbind.bss"; + else if ((s->flags & SEC_READONLY) == 0) + secname = ".mbind.data"; + else if ((s->flags & SEC_CODE) == 0) + secname = ".mbind.rodata"; + else + secname = ".mbind.text"; + } + /* Look through the script to see where to place this section. */ if (constraint == 0) for (os = lang_output_section_find (secname); @@ -2105,8 +2146,11 @@ gld${EMULATION_NAME}_place_orphan (asection *s, /* SEC_EXCLUDE is cleared when doing a relocatable link. But we can't merge 2 input sections with the same name when only - one of them has SHF_EXCLUDE. */ + one of them has SHF_EXCLUDE. Don't merge 2 sections with + different sh_info. */ if (os->bfd_section != NULL + && (elf_section_data (os->bfd_section)->this_hdr.sh_info + == elf_section_data (s)->this_hdr.sh_info) && (os->bfd_section->flags == 0 || ((!bfd_link_relocatable (&link_info) || (iself && (((elf_section_flags (s) diff --git a/ld/testsuite/ld-elf/elf.exp b/ld/testsuite/ld-elf/elf.exp index 09c9dda..f889070 100644 --- a/ld/testsuite/ld-elf/elf.exp +++ b/ld/testsuite/ld-elf/elf.exp @@ -298,6 +298,27 @@ if { [istarget *-*-linux*] || [istarget *-*-nacl*] || [istarget *-*-gnu*] } { run_ld_link_exec_tests $array_tests_pie $xfails + + run_ld_link_exec_tests [list \ + [list \ + "Run mbind2a" \ + "$NOPIE_LDFLAGS -Wl,-z,common-page-size=0x4000" \ + "" \ + { mbind2a.s mbind2b.c } \ + "mbind2a" \ + "pass.out" \ + "-O2 -I../bfd" \ + ] \ + [list \ + "Run mbind2b" \ + "-static -Wl,-z,common-page-size=0x4000" \ + "" \ + { mbind2a.s mbind2b.c } \ + "mbind2b" \ + "pass.out" \ + "-O2 -I../bfd" \ + ] \ + ] } # <http://www.gnu.org/software/hurd/open_issues/binutils.html#static> diff --git a/ld/testsuite/ld-elf/mbind1.s b/ld/testsuite/ld-elf/mbind1.s new file mode 100644 index 0000000..414b9fe --- /dev/null +++ b/ld/testsuite/ld-elf/mbind1.s @@ -0,0 +1,43 @@ + .text + .global start /* Used by SH targets. */ +start: + .global _start +_start: + .global __start +__start: + .global main /* Used by HPPA targets. */ +main: + .dc.a 0 + .section .mbind.data,"adw",%progbits + .byte 1 + + .section .mbind.data,"adw",%progbits,0x3 + .byte 2 + + .section .mbind.text,"adx",%progbits + .byte 3 + + .section .mbind.text,"adx",%progbits,0x3 + .byte 4 + + .section .mbind.bss,"adw",%nobits + .zero 5 + + .section .mbind.bss,"adw",%nobits,0x3 + .zero 6 + + .section .mbind.rodata,"adG",%progbits,.foo_group,comdat,0x2 + .byte 7 + + .section .mbind.data,"adGw",%progbits,.foo_group,comdat + .byte 8 + + .section .mbind.data,"adGw",%progbits,.foo_group,comdat,0x3 + .byte 9 + + # Check that .pushsection works as well. + .pushsection .mbind.text,"adGx",%progbits,.foo_group,comdat,0x3 + .byte 10 + + .popsection + .byte 11 diff --git a/ld/testsuite/ld-elf/mbind1a.d b/ld/testsuite/ld-elf/mbind1a.d new file mode 100644 index 0000000..aabf781 --- /dev/null +++ b/ld/testsuite/ld-elf/mbind1a.d @@ -0,0 +1,44 @@ +#source: mbind1.s +#ld: -z common-page-size=0x1000 -z max-page-size=0x200000 +#readelf: -S -l --wide +#target: *-*-linux* *-*-gnu* + +#... + \[[ 0-9]+\] \.mbind\.text[ ]+PROGBITS[ ]+[0-9a-f]+ [0-9a-f]+ [0-9a-f]+ 00 AXD 0 0 4096 + \[[ 0-9]+\] \.mbind\.text[ ]+PROGBITS[ ]+[0-9a-f]+ [0-9a-f]+ [0-9a-f]+ 00 AXD 0 3 4096 + \[[ 0-9]+\] \.mbind\.rodata[ ]+PROGBITS[ ]+[0-9a-f]+ [0-9a-f]+ [0-9a-f]+ 00 AD 0 2 4096 +#... + \[[ 0-9]+\] \.mbind\.data[ ]+PROGBITS[ ]+[0-9a-f]+ [0-9a-f]+ [0-9a-f]+ 00 WAD 0 0 4096 + \[[ 0-9]+\] \.mbind\.data[ ]+PROGBITS[ ]+[0-9a-f]+ [0-9a-f]+ [0-9a-f]+ 00 WAD 0 3 4096 +#... + \[[ 0-9]+\] \.mbind\.bss[ ]+NOBITS[ ]+[0-9a-f]+ [0-9a-f]+ [0-9a-f]+ 00 WAD 0 0 4096 + \[[ 0-9]+\] \.mbind\.bss[ ]+NOBITS[ ]+[0-9a-f]+ [0-9a-f]+ [0-9a-f]+ 00 WAD 0 3 4096 +#... +Program Headers: + Type.* +#... + LOAD[ \t]+0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ R E 0x200000 + LOAD[ \t]+0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ RW 0x200000 +#... + GNU_MBIND\+0[ \t]+0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ R E 0x1000 + GNU_MBIND\+0x3[ \t]+0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ R E 0x1000 + GNU_MBIND\+0x2[ \t]+0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ R 0x1000 + GNU_MBIND\+0[ \t]+0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ RW 0x1000 + GNU_MBIND\+0x3[ \t]+0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ RW 0x1000 + GNU_MBIND\+0[ \t]+0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ RW 0x1000 + GNU_MBIND\+0x3[ \t]+0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ RW 0x1000 +#... + Section to Segment mapping: + Segment Sections... +#... + [0-9]+ .*.text .mbind.text .mbind.text .mbind.rodata .* + [0-9]+ .*.mbind.data .mbind.data.* .mbind.bss .mbind.bss .* +#... + [0-9]+ .mbind.text + + [0-9]+ .mbind.text + + [0-9]+ .mbind.rodata + + [0-9]+ .mbind.data + + [0-9]+ .mbind.data + + [0-9]+ .mbind.bss + + [0-9]+ .mbind.bss + +#pass diff --git a/ld/testsuite/ld-elf/mbind1b.d b/ld/testsuite/ld-elf/mbind1b.d new file mode 100644 index 0000000..f161108 --- /dev/null +++ b/ld/testsuite/ld-elf/mbind1b.d @@ -0,0 +1,44 @@ +#source: mbind1.s +#ld: -shared -z common-page-size=0x1000 -z max-page-size=0x200000 +#readelf: -S -l --wide +#target: *-*-linux* *-*-gnu* + +#... + \[[ 0-9]+\] \.mbind\.text[ ]+PROGBITS[ ]+[0-9a-f]+ [0-9a-f]+ [0-9a-f]+ 00 AXD 0 0 4096 + \[[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9a-f]+ RW 0x1000 + GNU_MBIND\+0x3[ \t]+0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ RW 0x1000 + GNU_MBIND\+0[ \t]+0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ RW 0x1000 + GNU_MBIND\+0x3[ \t]+0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ RW 0x1000 +#... + Section to Segment mapping: + Segment Sections... +#... + [0-9]+ .*.text .mbind.text .mbind.text .mbind.rodata .* + [0-9]+ .*.mbind.data .mbind.data.* .mbind.bss .mbind.bss .* +#... + [0-9]+ .mbind.text + + [0-9]+ .mbind.text + + [0-9]+ .mbind.rodata + + [0-9]+ .mbind.data + + [0-9]+ .mbind.data + + [0-9]+ .mbind.bss + + [0-9]+ .mbind.bss + +#pass diff --git a/ld/testsuite/ld-elf/mbind1c.d b/ld/testsuite/ld-elf/mbind1c.d new file mode 100644 index 0000000..1348d0c --- /dev/null +++ b/ld/testsuite/ld-elf/mbind1c.d @@ -0,0 +1,44 @@ +#source: mbind1.s +#ld: -pie -z common-page-size=0x1000 -z max-page-size=0x200000 +#readelf: -S -l --wide +#target: *-*-linux* *-*-gnu* + +#... + \[[ 0-9]+\] \.mbind\.text[ ]+PROGBITS[ ]+[0-9a-f]+ [0-9a-f]+ [0-9a-f]+ 00 AXD 0 0 4096 + \[[ 0-9]+\] \.mbind\.text[ ]+PROGBITS[ ]+[0-9a-f]+ [0-9a-f]+ [0-9a-f]+ 00 AXD 0 3 4096 + \[[ 0-9]+\] \.mbind\.rodata[ ]+PROGBITS[ ]+[0-9a-f]+ [0-9a-f]+ [0-9a-f]+ 00 AD 0 2 4096 +#... + \[[ 0-9]+\] \.mbind\.data[ ]+PROGBITS[ ]+[0-9a-f]+ [0-9a-f]+ [0-9a-f]+ 00 WAD 0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-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ RW 0x1000 +#... + Section to Segment mapping: + Segment Sections... +#... + [0-9]+ .*.text .mbind.text .mbind.text .mbind.rodata .* + [0-9]+ .*.mbind.data .mbind.data.* .mbind.bss .mbind.bss .* +#... + [0-9]+ .mbind.text + + [0-9]+ .mbind.text + + [0-9]+ .mbind.rodata + + [0-9]+ .mbind.data + + [0-9]+ .mbind.data + + [0-9]+ .mbind.bss + + [0-9]+ .mbind.bss + +#pass diff --git a/ld/testsuite/ld-elf/mbind2a.s b/ld/testsuite/ld-elf/mbind2a.s new file mode 100644 index 0000000..2da9792 --- /dev/null +++ b/ld/testsuite/ld-elf/mbind2a.s @@ -0,0 +1,15 @@ +/* Place bss_in_mbind0 in .mbind.bss section with sh_info == 0. */ + .globl bss_in_mbind0 + .section .mbind.bss,"adw",@nobits,0 + .type bss_in_mbind0, @object + .size bss_in_mbind0, 1 +bss_in_mbind0: + .zero 1 + +/* Place data_in_mbind3 in .mbind.data section with sh_info == 3. */ + .globl data_in_mbind3 + .section .mbind.data,"adw",@progbits,0x3 + .type data_in_mbind3, @object + .size data_in_mbind3, 1 +data_in_mbind3: + .byte 0 diff --git a/ld/testsuite/ld-elf/mbind2b.c b/ld/testsuite/ld-elf/mbind2b.c new file mode 100644 index 0000000..10922a1 --- /dev/null +++ b/ld/testsuite/ld-elf/mbind2b.c @@ -0,0 +1,17 @@ +#include <stdio.h> +#include <stdlib.h> +#include <bfd_stdint.h> + +extern char bss_in_mbind0; +extern char data_in_mbind3; + +int +main (void) +{ + if (((intptr_t) &bss_in_mbind0 & (0x4000 - 1)) != 0) + abort (); + if (((intptr_t) &data_in_mbind3 & (0x4000 - 1)) != 0) + abort (); + printf ("PASS\n"); + return 0; +} |