From 12d814e1a0dc0a0cc351c2ce5c9c9ccacf5ec9b8 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Tue, 1 Aug 2006 17:50:52 +0000 Subject: [PATCH] ld/ 2006-08-01 H.J. Lu * ldlang.c (init_os): Add flags. Replace bfd_make_section with bfd_make_section_with_flags. (exp_init_os): Updated. (lang_add_section): Call init_os with flags. (map_input_to_output_sections): Likewise. ld/testsuite/ 2006-08-01 H.J. Lu * ld-elf/noload-1.d: New. * ld-elf/noload-1.s: Likewise. * ld-elf/noload-1.t: Likewise. --- ld/ChangeLog | 8 ++++ ld/ldlang.c | 76 ++++++++++++++++++---------------- ld/testsuite/ChangeLog | 6 +++ ld/testsuite/ld-elf/noload-1.d | 7 ++++ ld/testsuite/ld-elf/noload-1.s | 2 + ld/testsuite/ld-elf/noload-1.t | 8 ++++ 6 files changed, 72 insertions(+), 35 deletions(-) create mode 100644 ld/testsuite/ld-elf/noload-1.d create mode 100644 ld/testsuite/ld-elf/noload-1.s create mode 100644 ld/testsuite/ld-elf/noload-1.t diff --git a/ld/ChangeLog b/ld/ChangeLog index b0486f19796..f874f5dbfb3 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,11 @@ +2006-08-01 H.J. Lu + + * ldlang.c (init_os): Add flags. Replace bfd_make_section with + bfd_make_section_with_flags. + (exp_init_os): Updated. + (lang_add_section): Call init_os with flags. + (map_input_to_output_sections): Likewise. + 2006-07-29 Richard Sandiford * Makefile.am (eelf32b4300.c): Update dependencies. diff --git a/ld/ldlang.c b/ld/ldlang.c index 7938eb642a7..73d405365dd 100644 --- a/ld/ldlang.c +++ b/ld/ldlang.c @@ -1859,7 +1859,8 @@ sort_def_symbol (hash_entry, info) /* Initialize an output section. */ static void -init_os (lang_output_section_statement_type *s, asection *isec) +init_os (lang_output_section_statement_type *s, asection *isec, + flagword flags) { if (s->bfd_section != NULL) return; @@ -1869,7 +1870,8 @@ init_os (lang_output_section_statement_type *s, asection *isec) s->bfd_section = bfd_get_section_by_name (output_bfd, s->name); if (s->bfd_section == NULL) - s->bfd_section = bfd_make_section (output_bfd, s->name); + s->bfd_section = bfd_make_section_with_flags (output_bfd, s->name, + flags); if (s->bfd_section == NULL) { einfo (_("%P%F: output format %s cannot represent section called %s\n"), @@ -1947,7 +1949,7 @@ exp_init_os (etree_type *exp) os = lang_output_section_find (exp->name.name); if (os != NULL && os->bfd_section == NULL) - init_os (os, NULL); + init_os (os, NULL, 0); } } break; @@ -2022,8 +2024,32 @@ lang_add_section (lang_statement_list_type *ptr, lang_input_section_type *new; flagword flags; + flags = section->flags; + + /* We don't copy the SEC_NEVER_LOAD flag from an input section + to an output section, because we want to be able to include a + SEC_NEVER_LOAD section in the middle of an otherwise loaded + section (I don't know why we want to do this, but we do). + build_link_order in ldwrite.c handles this case by turning + the embedded SEC_NEVER_LOAD section into a fill. */ + + flags &= ~ SEC_NEVER_LOAD; + + switch (output->sectype) + { + case normal_section: + break; + case noalloc_section: + flags &= ~SEC_ALLOC; + break; + case noload_section: + flags &= ~SEC_LOAD; + flags |= SEC_NEVER_LOAD; + break; + } + if (output->bfd_section == NULL) - init_os (output, section); + init_os (output, section, flags); first = ! output->bfd_section->linker_has_input; output->bfd_section->linker_has_input = 1; @@ -2047,17 +2073,6 @@ lang_add_section (lang_statement_list_type *ptr, new->section = section; section->output_section = output->bfd_section; - flags = section->flags; - - /* We don't copy the SEC_NEVER_LOAD flag from an input section - to an output section, because we want to be able to include a - SEC_NEVER_LOAD section in the middle of an otherwise loaded - section (I don't know why we want to do this, but we do). - build_link_order in ldwrite.c handles this case by turning - the embedded SEC_NEVER_LOAD section into a fill. */ - - flags &= ~ SEC_NEVER_LOAD; - /* If final link, don't copy the SEC_LINK_ONCE flags, they've already been processed. One reason to do this is that on pe format targets, .text$foo sections go into .text and it's odd @@ -2094,19 +2109,6 @@ lang_add_section (lang_statement_list_type *ptr, if ((section->flags & SEC_READONLY) == 0) output->bfd_section->flags &= ~SEC_READONLY; - switch (output->sectype) - { - case normal_section: - break; - case noalloc_section: - output->bfd_section->flags &= ~SEC_ALLOC; - break; - case noload_section: - output->bfd_section->flags &= ~SEC_LOAD; - output->bfd_section->flags |= SEC_NEVER_LOAD; - break; - } - /* Copy over SEC_SMALL_DATA. */ if (section->flags & SEC_SMALL_DATA) output->bfd_section->flags |= SEC_SMALL_DATA; @@ -3201,6 +3203,8 @@ map_input_to_output_sections (lang_statement_union_type *s, const char *target, lang_output_section_statement_type *os) { + flagword flags; + for (; s != NULL; s = s->header.next) { switch (s->header.type) @@ -3250,13 +3254,15 @@ map_input_to_output_sections /* Make sure that any sections mentioned in the expression are initialized. */ exp_init_os (s->data_statement.exp); - if (os != NULL && os->bfd_section == NULL) - init_os (os, NULL); + flags = SEC_HAS_CONTENTS; /* The output section gets contents, and then we inspect for any flags set in the input script which override any ALLOC. */ - os->bfd_section->flags |= SEC_HAS_CONTENTS; if (!(os->flags & SEC_NEVER_LOAD)) - os->bfd_section->flags |= SEC_ALLOC | SEC_LOAD; + flags |= SEC_ALLOC | SEC_LOAD; + if (os->bfd_section == NULL) + init_os (os, NULL, flags); + else + os->bfd_section->flags |= flags; break; case lang_input_section_enum: break; @@ -3266,11 +3272,11 @@ map_input_to_output_sections case lang_padding_statement_enum: case lang_input_statement_enum: if (os != NULL && os->bfd_section == NULL) - init_os (os, NULL); + init_os (os, NULL, 0); break; case lang_assignment_statement_enum: if (os != NULL && os->bfd_section == NULL) - init_os (os, NULL); + init_os (os, NULL, 0); /* Make sure that any sections mentioned in the assignment are initialized. */ @@ -3298,7 +3304,7 @@ map_input_to_output_sections (s->address_statement.section_name)); if (aos->bfd_section == NULL) - init_os (aos, NULL); + init_os (aos, NULL, 0); aos->addr_tree = s->address_statement.address; } break; diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog index 92b8a2de890..80f009413e4 100644 --- a/ld/testsuite/ChangeLog +++ b/ld/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2006-08-01 H.J. Lu + + * ld-elf/noload-1.d: New. + * ld-elf/noload-1.s: Likewise. + * ld-elf/noload-1.t: Likewise. + 2006-07-29 Richard Sandiford * ld-mips-elf/hash1.s, ld-mips-elf/hash1a.d, diff --git a/ld/testsuite/ld-elf/noload-1.d b/ld/testsuite/ld-elf/noload-1.d new file mode 100644 index 00000000000..7cae479a071 --- /dev/null +++ b/ld/testsuite/ld-elf/noload-1.d @@ -0,0 +1,7 @@ +#source: noload-1.s +#ld: -T noload-1.t +#readelf: -S --wide + +#... + \[[ 0-9]+\] TEST[ \t]+NOBITS[ \t0-9a-f]+WA.* +#pass diff --git a/ld/testsuite/ld-elf/noload-1.s b/ld/testsuite/ld-elf/noload-1.s new file mode 100644 index 00000000000..ad0479e0e47 --- /dev/null +++ b/ld/testsuite/ld-elf/noload-1.s @@ -0,0 +1,2 @@ + .section TEST,"aw",%progbits + .byte 0 diff --git a/ld/testsuite/ld-elf/noload-1.t b/ld/testsuite/ld-elf/noload-1.t new file mode 100644 index 00000000000..1efd06c2e11 --- /dev/null +++ b/ld/testsuite/ld-elf/noload-1.t @@ -0,0 +1,8 @@ +SECTIONS +{ + TEST (NOLOAD) : + { + *(TEST) + } + /DISCARD/ : { *(.*) } +} -- 2.30.2