diff options
author | Alan Modra <amodra@gmail.com> | 2019-11-26 16:49:44 +1030 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2019-12-26 17:49:03 +1030 |
commit | 8ce18f9cdf53c846e0486130a66ba55c96fc2b14 (patch) | |
tree | 00869e348fe72b0b9165e3858861254b9489fc37 /ld/emultempl | |
parent | 100b122fc125bdf1fe768a3331a0cd413c3d1261 (diff) | |
download | gdb-8ce18f9cdf53c846e0486130a66ba55c96fc2b14.zip gdb-8ce18f9cdf53c846e0486130a66ba55c96fc2b14.tar.gz gdb-8ce18f9cdf53c846e0486130a66ba55c96fc2b14.tar.bz2 |
Avoid ubsan bug complaining about &p->field
I reckon it's quite OK to write &p->field in C when p might be NULL,
and lots of old C programmers probably agree with me. However, ubsan
disagrees and so do some people I respect. I suspect C++ influence is
to blame for the ubsan behaviour. See
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92634. So far no one has
educated me as to why I'm wrong to claim that there isn't anything in
the C standard to say that p->field is always (*p).field. Note 79
doesn't quite do that because it doesn't cover null pointers. If
there was such an equivalence then you could claim &p->field has a
null pointer reference when p is NULL, even though no C compiler would
ever dereference p.
Anyway, to silence ubsan I'm going to apply the following though I
prefer to avoid casts when possible. And I'm using (void *)
deliberately because this is C, not C++!
* ldlang.c (lang_output_section_find_by_flags): Don't use &p->field
when p might be NULL.
* ldelf.c (output_rel_find, ldelf_place_orphan): Likewise.
(insert_os_after, lang_insert_orphan, lookup_name): Likewise.
(strip_excluded_output_sections, lang_clear_os_map): Likewise.
(lang_check, lang_for_each_input_file): Likewise.
(lang_reset_memory_regions, find_replacements_insert_point): Likewise.
(find_rescan_insertion, lang_propagate_lma_regions): Likewise.
(lang_record_phdrs): Likewise.
* emultempl/alphaelf.em (alpha_after_open): Likewise.
* emultempl/mmo.em (mmo_place_orphan): Likewise.
* emultempl/pe.em (gld_${EMULATION_NAME}_place_orphan): Likewise.
* emultempl/pep.em (gld_${EMULATION_NAME}_place_orphan): Likewise.
* emultempl/ppc32elf.em (ppc_after_check_relocs): Likewise.
* emultempl/spuelf.em (spu_before_allocation): Likewise.
(embedded_spu_file): Likewise.
Diffstat (limited to 'ld/emultempl')
-rw-r--r-- | ld/emultempl/alphaelf.em | 2 | ||||
-rw-r--r-- | ld/emultempl/mmo.em | 2 | ||||
-rw-r--r-- | ld/emultempl/pe.em | 2 | ||||
-rw-r--r-- | ld/emultempl/pep.em | 2 | ||||
-rw-r--r-- | ld/emultempl/ppc32elf.em | 2 | ||||
-rw-r--r-- | ld/emultempl/spuelf.em | 4 |
6 files changed, 7 insertions, 7 deletions
diff --git a/ld/emultempl/alphaelf.em b/ld/emultempl/alphaelf.em index 4e7886f..db53d51 100644 --- a/ld/emultempl/alphaelf.em +++ b/ld/emultempl/alphaelf.em @@ -47,7 +47,7 @@ alpha_after_open (void) lang_output_section_statement_type *plt_os[2]; num_plt = 0; - for (os = &lang_os_list.head->output_section_statement; + for (os = (void *) lang_os_list.head; os != NULL; os = os->next) { diff --git a/ld/emultempl/mmo.em b/ld/emultempl/mmo.em index 85c5863..247d8a8 100644 --- a/ld/emultempl/mmo.em +++ b/ld/emultempl/mmo.em @@ -163,7 +163,7 @@ mmo_place_orphan (asection *s, /* We have to find the oss before this one, so we can use that as "after". */ - for (lookup = &lang_os_list.head->output_section_statement; + for (lookup = (void *) lang_os_list.head; lookup != NULL && lookup->next != before; lookup = lookup->next) ; diff --git a/ld/emultempl/pe.em b/ld/emultempl/pe.em index c4c6464..7e85ede 100644 --- a/ld/emultempl/pe.em +++ b/ld/emultempl/pe.em @@ -2151,7 +2151,7 @@ gld_${EMULATION_NAME}_place_orphan (asection *s, NULL); if (after == NULL) /* *ABS* is always the first output section statement. */ - after = &lang_os_list.head->output_section_statement; + after = (void *) lang_os_list.head; } /* All sections in an executable must be aligned to a page boundary. diff --git a/ld/emultempl/pep.em b/ld/emultempl/pep.em index ec2d83f..f9f6a8e 100644 --- a/ld/emultempl/pep.em +++ b/ld/emultempl/pep.em @@ -1950,7 +1950,7 @@ gld_${EMULATION_NAME}_place_orphan (asection *s, NULL); if (after == NULL) /* *ABS* is always the first output section statement. */ - after = &lang_os_list.head->output_section_statement; + after = (void *) lang_os_list.head; } /* All sections in an executable must be aligned to a page boundary. diff --git a/ld/emultempl/ppc32elf.em b/ld/emultempl/ppc32elf.em index 056068e..78a2eb1 100644 --- a/ld/emultempl/ppc32elf.em +++ b/ld/emultempl/ppc32elf.em @@ -79,7 +79,7 @@ ppc_after_check_relocs (void) num_got = 0; num_plt = 0; - for (os = &lang_os_list.head->output_section_statement; + for (os = (void *) lang_os_list.head; os != NULL; os = os->next) { diff --git a/ld/emultempl/spuelf.em b/ld/emultempl/spuelf.em index 40a757a..96ac86f 100644 --- a/ld/emultempl/spuelf.em +++ b/ld/emultempl/spuelf.em @@ -290,7 +290,7 @@ spu_before_allocation (void) } /* Ensure alignment of overlay sections is sufficient. */ - for (os = &lang_os_list.head->output_section_statement; + for (os = (void *) lang_os_list.head; os != NULL; os = os->next) if (os->bfd_section != NULL @@ -512,7 +512,7 @@ embedded_spu_file (lang_input_statement_type *entry, const char *flags) return FALSE; close (fd); - for (search = &input_file_chain.head->input_statement; + for (search = (void *) input_file_chain.head; search != NULL; search = search->next_real_file) if (search->filename != NULL) |