aboutsummaryrefslogtreecommitdiff
path: root/gas/config
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2017-04-04 09:05:48 -0700
committerH.J. Lu <hjl.tools@gmail.com>2017-04-04 09:06:04 -0700
commita91e1603afb6704545793e967a1a3dfe96b389de (patch)
tree631a0fd733778fbcc14c12f41c4fdb88f3348737 /gas/config
parentb52920324fabbcad93042f2e17de52696d0dab42 (diff)
downloadgdb-a91e1603afb6704545793e967a1a3dfe96b389de.zip
gdb-a91e1603afb6704545793e967a1a3dfe96b389de.tar.gz
gdb-a91e1603afb6704545793e967a1a3dfe96b389de.tar.bz2
Support ELF SHF_GNU_MBIND and PT_GNU_MBIND_XXX
Mark an ALLOC section, which should be placed in special memory area, with SHF_GNU_MBIND. Its sh_info field indicates the special memory type. GNU_MBIND section names start with ".mbind" so that they are placed as orphan sections by linker. All input GNU_MBIND sections with the same sh_type, sh_flags and sh_info are placed in one output GNU_MBIND section. In executable and shared object, create a GNU_MBIND segment for each GNU_MBIND section and its segment type is PT_GNU_MBIND_LO plus the sh_info value. Each GNU_MBIND segment is aligned at page boundary. The assembler syntax: .section .mbind.foo,"adx",%progbits ^ 0: Special memory type. | 'd' for SHF_GNU_MBIND. .section .mbind.foo,"adx",%progbits,0x1 ^ 1: Special memory type. | 'd' for SHF_GNU_MBIND. .section .mbind.bar,"adG",%progbits,.foo_group,comdat,0x2 ^ 2: Special memory type. | 'd' for SHF_GNU_MBIND. bfd/ * elf.c (get_program_header_size): Add a GNU_MBIND segment for each GNU_MBIND section and align GNU_MBIND section to page size. (_bfd_elf_map_sections_to_segments): Create a GNU_MBIND segment for each GNU_MBIND section. (_bfd_elf_init_private_section_data): Copy sh_info from input for GNU_MBIND section. binutils/ * NEWS: Mention support for ELF SHF_GNU_MBIND and PT_GNU_MBIND_XXX. * readelf.c (get_segment_type): Handle PT_GNU_MBIND_XXX. (get_elf_section_flags): Handle SHF_GNU_MBIND. (process_section_headers): Likewise. * testsuite/binutils-all/mbind1.s: New file. * testsuite/binutils-all/objcopy.exp: Run readelf test on mbind1.s. gas/ * NEWS: Mention support for ELF SHF_GNU_MBIND. * config/obj-elf.c (section_match): New. (get_section): Match both sh_info and group name. (obj_elf_change_section): Add argument for sh_info. Pass both sh_info and group name to get_section. Issue an error for SHF_GNU_MBIND section without SHF_ALLOC. Set sh_info. (obj_elf_parse_section_letters): Set SHF_GNU_MBIND for 'd'. (obj_elf_section): Support SHF_GNU_MBIND section info. * config/obj-elf.h (obj_elf_change_section): Add argument for sh_info. * config/tc-arm.c (start_unwind_section): Pass 0 as sh_info to obj_elf_change_section. * config/tc-ia64.c (obj_elf_vms_common): Likewise. * config/tc-microblaze.c (microblaze_s_data): Likewise. (microblaze_s_sdata): Likewise. (microblaze_s_rdata): Likewise. (microblaze_s_bss): Likewise. * config/tc-mips.c (s_change_section): Likewise. * config/tc-msp430.c (msp430_profiler): Likewise. * config/tc-rx.c (parse_rx_section): Likewise. * config/tc-tic6x.c (tic6x_start_unwind_section): Likewise. * doc/as.texinfo: Document 'd' for SHF_GNU_MBIND. * testsuite/gas/elf/elf.exp: Run section12a, section12b and section13. * testsuite/gas/elf/section10.d: Updated. * testsuite/gas/elf/section10.s: Likewise. * testsuite/gas/elf/section12.s: New file. * testsuite/gas/elf/section12a.d: Likewise. * testsuite/gas/elf/section12b.d: Likewise. * testsuite/gas/elf/section13.l: Likewise. * testsuite/gas/elf/section13.d: Likewise. * testsuite/gas/elf/section13.s: Likewise. include/ * elf/common.h (PT_GNU_MBIND_NUM): New. (PT_GNU_MBIND_LO): Likewise. (PT_GNU_MBIND_HI): Likewise. (SHF_GNU_MBIND): Likewise. ld/ * 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.
Diffstat (limited to 'gas/config')
-rw-r--r--gas/config/obj-elf.c54
-rw-r--r--gas/config/obj-elf.h3
-rw-r--r--gas/config/tc-arm.c3
-rw-r--r--gas/config/tc-ia64.c2
-rw-r--r--gas/config/tc-microblaze.c18
-rw-r--r--gas/config/tc-mips.c2
-rw-r--r--gas/config/tc-msp430.c2
-rw-r--r--gas/config/tc-rx.c4
-rw-r--r--gas/config/tc-tic6x.c3
9 files changed, 70 insertions, 21 deletions
diff --git a/gas/config/obj-elf.c b/gas/config/obj-elf.c
index 1d59fc0..3696d5e 100644
--- a/gas/config/obj-elf.c
+++ b/gas/config/obj-elf.c
@@ -520,16 +520,26 @@ struct section_stack
static struct section_stack *section_stack;
+/* Match both section group name and the sh_info field. */
+struct section_match
+{
+ const char *group_name;
+ unsigned int info;
+};
+
static bfd_boolean
get_section (bfd *abfd ATTRIBUTE_UNUSED, asection *sec, void *inf)
{
- const char *gname = (const char *) inf;
+ struct section_match *match = (struct section_match *) inf;
+ const char *gname = match->group_name;
const char *group_name = elf_group_name (sec);
+ unsigned int info = elf_section_data (sec)->this_hdr.sh_info;
- return (group_name == gname
- || (group_name != NULL
- && gname != NULL
- && strcmp (group_name, gname) == 0));
+ return (info == match->info
+ && (group_name == gname
+ || (group_name != NULL
+ && gname != NULL
+ && strcmp (group_name, gname) == 0)));
}
/* Handle the .section pseudo-op. This code supports two different
@@ -553,6 +563,7 @@ get_section (bfd *abfd ATTRIBUTE_UNUSED, asection *sec, void *inf)
void
obj_elf_change_section (const char *name,
unsigned int type,
+ unsigned int info,
bfd_vma attr,
int entsize,
const char *group_name,
@@ -564,6 +575,7 @@ obj_elf_change_section (const char *name,
flagword flags;
const struct elf_backend_data *bed;
const struct bfd_elf_special_section *ssect;
+ struct section_match match;
#ifdef md_flush_pending_output
md_flush_pending_output ();
@@ -584,8 +596,10 @@ obj_elf_change_section (const char *name,
previous_section = now_seg;
previous_subsection = now_subseg;
+ match.group_name = group_name;
+ match.info = info;
old_sec = bfd_get_section_by_name_if (stdoutput, name, get_section,
- (void *) group_name);
+ (void *) &match);
if (old_sec)
{
sec = old_sec;
@@ -695,6 +709,9 @@ obj_elf_change_section (const char *name,
attr |= ssect->attr;
}
+ if ((attr & (SHF_ALLOC | SHF_GNU_MBIND)) == SHF_GNU_MBIND)
+ as_fatal (_("SHF_ALLOC isn't set for GNU_MBIND section: %s"), name);
+
/* Convert ELF type and flags to BFD flags. */
flags = (SEC_RELOC
| ((attr & SHF_WRITE) ? 0 : SEC_READONLY)
@@ -720,6 +737,7 @@ obj_elf_change_section (const char *name,
type = bfd_elf_get_default_section_type (flags);
elf_section_type (sec) = type;
elf_section_flags (sec) = attr;
+ elf_section_data (sec)->this_hdr.sh_info = info;
/* Prevent SEC_HAS_CONTENTS from being inadvertently set. */
if (type == SHT_NOBITS)
@@ -803,6 +821,9 @@ obj_elf_parse_section_letters (char *str, size_t len, bfd_boolean *is_clone)
case 'T':
attr |= SHF_TLS;
break;
+ case 'd':
+ attr |= SHF_GNU_MBIND;
+ break;
case '?':
*is_clone = TRUE;
break;
@@ -996,6 +1017,7 @@ obj_elf_section (int push)
int entsize;
int linkonce;
subsegT new_subsection = -1;
+ unsigned int info = 0;
#ifndef TC_I370
if (flag_mri)
@@ -1159,6 +1181,23 @@ obj_elf_section (int push)
linkonce = (now_seg->flags & SEC_LINK_ONCE) != 0;
}
}
+
+ if ((attr & SHF_GNU_MBIND) != 0 && *input_line_pointer == ',')
+ {
+ ++input_line_pointer;
+ SKIP_WHITESPACE ();
+ if (ISDIGIT (* input_line_pointer))
+ {
+ char *t = input_line_pointer;
+ info = strtoul (input_line_pointer,
+ &input_line_pointer, 0);
+ if (info == (unsigned int) -1)
+ {
+ as_warn (_("unsupported mbind section info: %s"), t);
+ info = 0;
+ }
+ }
+ }
}
else
{
@@ -1189,7 +1228,8 @@ obj_elf_section (int push)
done:
demand_empty_rest_of_line ();
- obj_elf_change_section (name, type, attr, entsize, group_name, linkonce, push);
+ obj_elf_change_section (name, type, info, attr, entsize, group_name,
+ linkonce, push);
if (push && new_subsection != -1)
subseg_set (now_seg, new_subsection);
diff --git a/gas/config/obj-elf.h b/gas/config/obj-elf.h
index f6bd216..37d6aee 100644
--- a/gas/config/obj-elf.h
+++ b/gas/config/obj-elf.h
@@ -162,7 +162,8 @@ extern void obj_elf_common (int);
extern void obj_elf_data (int);
extern void obj_elf_text (int);
extern void obj_elf_change_section
- (const char *, unsigned int, bfd_vma, int, const char *, int, int);
+ (const char *, unsigned int, unsigned int, bfd_vma, int, const char *,
+ int, int);
extern struct fix *obj_elf_vtable_inherit (int);
extern struct fix *obj_elf_vtable_entry (int);
extern bfd_boolean obj_elf_seen_attribute
diff --git a/gas/config/tc-arm.c b/gas/config/tc-arm.c
index bbfe634..83244b7 100644
--- a/gas/config/tc-arm.c
+++ b/gas/config/tc-arm.c
@@ -22113,7 +22113,8 @@ start_unwind_section (const segT text_seg, int idx)
linkonce = 1;
}
- obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
+ obj_elf_change_section (sec_name, type, 0, flags, 0, group_name,
+ linkonce, 0);
/* Set the section link for index tables. */
if (idx)
diff --git a/gas/config/tc-ia64.c b/gas/config/tc-ia64.c
index aa01eff..e236dd5 100644
--- a/gas/config/tc-ia64.c
+++ b/gas/config/tc-ia64.c
@@ -1139,7 +1139,7 @@ obj_elf_vms_common (int ignore ATTRIBUTE_UNUSED)
demand_empty_rest_of_line ();
obj_elf_change_section
- (sec_name, SHT_NOBITS,
+ (sec_name, SHT_NOBITS, 0,
SHF_ALLOC | SHF_WRITE | SHF_IA_64_VMS_OVERLAID | SHF_IA_64_VMS_GLOBAL,
0, NULL, 1, 0);
diff --git a/gas/config/tc-microblaze.c b/gas/config/tc-microblaze.c
index c3b091f..0124422 100644
--- a/gas/config/tc-microblaze.c
+++ b/gas/config/tc-microblaze.c
@@ -145,7 +145,8 @@ static void
microblaze_s_data (int ignore ATTRIBUTE_UNUSED)
{
#ifdef OBJ_ELF
- obj_elf_change_section (".data", SHT_PROGBITS, SHF_ALLOC+SHF_WRITE, 0, 0, 0, 0);
+ obj_elf_change_section (".data", SHT_PROGBITS, 0, SHF_ALLOC+SHF_WRITE,
+ 0, 0, 0, 0);
#else
s_data (ignore);
#endif
@@ -157,7 +158,8 @@ static void
microblaze_s_sdata (int ignore ATTRIBUTE_UNUSED)
{
#ifdef OBJ_ELF
- obj_elf_change_section (".sdata", SHT_PROGBITS, SHF_ALLOC+SHF_WRITE, 0, 0, 0, 0);
+ obj_elf_change_section (".sdata", SHT_PROGBITS, 0, SHF_ALLOC+SHF_WRITE,
+ 0, 0, 0, 0);
#else
s_data (ignore);
#endif
@@ -275,14 +277,16 @@ microblaze_s_rdata (int localvar)
if (localvar == 0)
{
/* rodata. */
- obj_elf_change_section (".rodata", SHT_PROGBITS, SHF_ALLOC, 0, 0, 0, 0);
+ obj_elf_change_section (".rodata", SHT_PROGBITS, 0, SHF_ALLOC,
+ 0, 0, 0, 0);
if (rodata_segment == 0)
rodata_segment = subseg_new (".rodata", 0);
}
else
{
/* 1 .sdata2. */
- obj_elf_change_section (".sdata2", SHT_PROGBITS, SHF_ALLOC, 0, 0, 0, 0);
+ obj_elf_change_section (".sdata2", SHT_PROGBITS, 0, SHF_ALLOC,
+ 0, 0, 0, 0);
}
#else
s_data (ignore);
@@ -294,11 +298,13 @@ microblaze_s_bss (int localvar)
{
#ifdef OBJ_ELF
if (localvar == 0) /* bss. */
- obj_elf_change_section (".bss", SHT_NOBITS, SHF_ALLOC+SHF_WRITE, 0, 0, 0, 0);
+ obj_elf_change_section (".bss", SHT_NOBITS, 0, SHF_ALLOC+SHF_WRITE,
+ 0, 0, 0, 0);
else if (localvar == 1)
{
/* sbss. */
- obj_elf_change_section (".sbss", SHT_NOBITS, SHF_ALLOC+SHF_WRITE, 0, 0, 0, 0);
+ obj_elf_change_section (".sbss", SHT_NOBITS, 0, SHF_ALLOC+SHF_WRITE,
+ 0, 0, 0, 0);
if (sbss_segment == 0)
sbss_segment = subseg_new (".sbss", 0);
}
diff --git a/gas/config/tc-mips.c b/gas/config/tc-mips.c
index 54b94be..6a98122 100644
--- a/gas/config/tc-mips.c
+++ b/gas/config/tc-mips.c
@@ -15879,7 +15879,7 @@ s_change_section (int ignore ATTRIBUTE_UNUSED)
if (section_type == SHT_MIPS_DWARF)
section_type = SHT_PROGBITS;
- obj_elf_change_section (section_name, section_type, section_flag,
+ obj_elf_change_section (section_name, section_type, 0, section_flag,
section_entry_size, 0, 0, 0);
if (now_seg->name != section_name)
diff --git a/gas/config/tc-msp430.c b/gas/config/tc-msp430.c
index a24771b..10e5972 100644
--- a/gas/config/tc-msp430.c
+++ b/gas/config/tc-msp430.c
@@ -612,7 +612,7 @@ msp430_profiler (int dummy ATTRIBUTE_UNUSED)
subseg = now_subseg;
/* Now go to .profiler section. */
- obj_elf_change_section (".profiler", SHT_PROGBITS, 0, 0, 0, 0, 0);
+ obj_elf_change_section (".profiler", SHT_PROGBITS, 0, 0, 0, 0, 0, 0);
/* Save flags. */
emit_expr (& exp, 2);
diff --git a/gas/config/tc-rx.c b/gas/config/tc-rx.c
index 05fa4da..ba826c7 100644
--- a/gas/config/tc-rx.c
+++ b/gas/config/tc-rx.c
@@ -486,7 +486,7 @@ parse_rx_section (char * name)
else
type = SHT_NOBITS;
- obj_elf_change_section (name, type, attr, 0, NULL, FALSE, FALSE);
+ obj_elf_change_section (name, type, 0, attr, 0, NULL, FALSE, FALSE);
}
else /* Try not to redefine a section, especially B_1. */
{
@@ -501,7 +501,7 @@ parse_rx_section (char * name)
| ((flags & SEC_STRINGS) ? SHF_STRINGS : 0)
| ((flags & SEC_THREAD_LOCAL) ? SHF_TLS : 0);
- obj_elf_change_section (name, type, attr, 0, NULL, FALSE, FALSE);
+ obj_elf_change_section (name, type, 0, attr, 0, NULL, FALSE, FALSE);
}
bfd_set_section_alignment (stdoutput, now_seg, align);
diff --git a/gas/config/tc-tic6x.c b/gas/config/tc-tic6x.c
index c75fcf6..6958a0e 100644
--- a/gas/config/tc-tic6x.c
+++ b/gas/config/tc-tic6x.c
@@ -4666,7 +4666,8 @@ tic6x_start_unwind_section (const segT text_seg, int idx)
linkonce = 1;
}
- obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
+ obj_elf_change_section (sec_name, type, 0, flags, 0, group_name,
+ linkonce, 0);
/* Set the section link for index tables. */
if (idx)