X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=ld%2Fldlang.c;h=f51f68ef4b09054443d600bb8018f596dd2efb97;hb=218868ba41c7305c13c7b4c7e781cabeb11dce62;hp=119fb7aefcfec4bcc5202825a6637efd6ba8501b;hpb=be5291325d6402206276092e018ad6bb4210bcf0;p=deliverable%2Fbinutils-gdb.git diff --git a/ld/ldlang.c b/ld/ldlang.c index 119fb7aefc..f51f68ef4b 100644 --- a/ld/ldlang.c +++ b/ld/ldlang.c @@ -912,8 +912,14 @@ output_statement_newfunc (struct bfd_hash_entry *entry, (lang_statement_union_type *) &ret->os, &ret->os.header.next); - ret->os.prev = &((*lang_output_section_statement.tail) - ->output_section_statement); + /* For every output section statement added to the list, except the + first one, lang_output_section_statement.tail points to the "next" + field of the last element of the list. */ + if (lang_output_section_statement.head != NULL) + ret->os.prev = (lang_output_section_statement_type *) + ((char *) lang_output_section_statement.tail + - offsetof (lang_output_section_statement_type, next)); + /* GCC's strict aliasing rules prevent us from just casting the address, so we store the pointer in a variable and cast that instead. */ @@ -1147,7 +1153,8 @@ lang_output_section_statement_lookup (const char *const name) lang_output_section_statement_type * lang_output_section_find_by_flags (const asection *sec, - lang_output_section_statement_type **exact) + lang_output_section_statement_type **exact, + lang_match_sec_type_func match_type) { lang_output_section_statement_type *first, *look, *found; flagword flags; @@ -1165,9 +1172,8 @@ lang_output_section_find_by_flags (const asection *sec, if (look->bfd_section != NULL) { flags = look->bfd_section->flags; - if (!bfd_match_sections_by_type (output_bfd, - look->bfd_section, - sec->owner, sec)) + if (match_type && !match_type (output_bfd, look->bfd_section, + sec->owner, sec)) continue; } flags ^= sec->flags; @@ -1177,7 +1183,8 @@ lang_output_section_find_by_flags (const asection *sec, } if (found != NULL) { - *exact = found; + if (exact != NULL) + *exact = found; return found; } @@ -1190,9 +1197,8 @@ lang_output_section_find_by_flags (const asection *sec, if (look->bfd_section != NULL) { flags = look->bfd_section->flags; - if (!bfd_match_sections_by_type (output_bfd, - look->bfd_section, - sec->owner, sec)) + if (match_type && !match_type (output_bfd, look->bfd_section, + sec->owner, sec)) continue; } flags ^= sec->flags; @@ -1200,10 +1206,8 @@ lang_output_section_find_by_flags (const asection *sec, | SEC_CODE | SEC_SMALL_DATA | SEC_THREAD_LOCAL))) found = look; } - return found; } - - if (sec->flags & (SEC_READONLY | SEC_THREAD_LOCAL)) + else if (sec->flags & (SEC_READONLY | SEC_THREAD_LOCAL)) { /* .rodata can go after .text, .sdata2 after .rodata. */ for (look = first; look; look = look->next) @@ -1212,9 +1216,8 @@ lang_output_section_find_by_flags (const asection *sec, if (look->bfd_section != NULL) { flags = look->bfd_section->flags; - if (!bfd_match_sections_by_type (output_bfd, - look->bfd_section, - sec->owner, sec)) + if (match_type && !match_type (output_bfd, look->bfd_section, + sec->owner, sec)) continue; } flags ^= sec->flags; @@ -1223,10 +1226,8 @@ lang_output_section_find_by_flags (const asection *sec, && !(look->flags & (SEC_SMALL_DATA | SEC_THREAD_LOCAL))) found = look; } - return found; } - - if (sec->flags & SEC_SMALL_DATA) + else if (sec->flags & SEC_SMALL_DATA) { /* .sdata goes after .data, .sbss after .sdata. */ for (look = first; look; look = look->next) @@ -1235,9 +1236,8 @@ lang_output_section_find_by_flags (const asection *sec, if (look->bfd_section != NULL) { flags = look->bfd_section->flags; - if (!bfd_match_sections_by_type (output_bfd, - look->bfd_section, - sec->owner, sec)) + if (match_type && !match_type (output_bfd, look->bfd_section, + sec->owner, sec)) continue; } flags ^= sec->flags; @@ -1247,10 +1247,8 @@ lang_output_section_find_by_flags (const asection *sec, && !(sec->flags & SEC_HAS_CONTENTS))) found = look; } - return found; } - - if (sec->flags & SEC_HAS_CONTENTS) + else if (sec->flags & SEC_HAS_CONTENTS) { /* .data goes after .rodata. */ for (look = first; look; look = look->next) @@ -1259,9 +1257,8 @@ lang_output_section_find_by_flags (const asection *sec, if (look->bfd_section != NULL) { flags = look->bfd_section->flags; - if (!bfd_match_sections_by_type (output_bfd, - look->bfd_section, - sec->owner, sec)) + if (match_type && !match_type (output_bfd, look->bfd_section, + sec->owner, sec)) continue; } flags ^= sec->flags; @@ -1269,27 +1266,30 @@ lang_output_section_find_by_flags (const asection *sec, | SEC_SMALL_DATA | SEC_THREAD_LOCAL))) found = look; } - return found; } - - /* .bss goes last. */ - for (look = first; look; look = look->next) + else { - flags = look->flags; - if (look->bfd_section != NULL) + /* .bss goes last. */ + for (look = first; look; look = look->next) { - flags = look->bfd_section->flags; - if (!bfd_match_sections_by_type (output_bfd, - look->bfd_section, - sec->owner, sec)) - continue; + flags = look->flags; + if (look->bfd_section != NULL) + { + flags = look->bfd_section->flags; + if (match_type && !match_type (output_bfd, look->bfd_section, + sec->owner, sec)) + continue; + } + flags ^= sec->flags; + if (!(flags & SEC_ALLOC)) + found = look; } - flags ^= sec->flags; - if (!(flags & SEC_ALLOC)) - found = look; } - return found; + if (found || !match_type) + return found; + + return lang_output_section_find_by_flags (sec, NULL, NULL); } /* Find the last output section before given output statement. @@ -1547,7 +1547,12 @@ lang_insert_orphan (asection *s, /* Do the same for the list of output section statements. */ newly_added_os = *os_tail; *os_tail = NULL; + newly_added_os->prev = (lang_output_section_statement_type *) + ((char *) place->os_tail + - offsetof (lang_output_section_statement_type, next)); newly_added_os->next = *place->os_tail; + if (newly_added_os->next != NULL) + newly_added_os->next->prev = newly_added_os; *place->os_tail = newly_added_os; place->os_tail = &newly_added_os->next;