[RFC] ld: fix --non-contiguous-regions error checks
Checks
Context |
Check |
Description |
linaro-tcwg-bot/tcwg_binutils_build--master-arm |
success
|
Testing passed
|
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 |
success
|
Testing passed
|
linaro-tcwg-bot/tcwg_binutils_check--master-aarch64 |
success
|
Testing passed
|
linaro-tcwg-bot/tcwg_binutils_check--master-arm |
fail
|
Testing failed
|
Commit Message
- Fix segmentation fault in _bfd_riscv_relax_section():
sym_sec->output_sectioin nullptr dereference
https://github.com/bminor/binutils-gdb/blob/binutils-2_41-release/bfd/elfnn-riscv.c#L5207
- Fatal error only for sections that has SEC_RELOC flag when a segment
overflows. It allows to write sections with SEC_MERGE flag to next
segment.
In case changes are good to go there are also some workarounds in the code these should be removed.
Like this:
https://github.com/bminor/binutils-gdb/blob/binutils-2_41-release/bfd/elf32-arm.c#L5052-L5058
---
ld/ldlang.c | 22 ++++++++++++-------
ld/testsuite/ld-arm/non-contiguous-arm.d | 2 +-
ld/testsuite/ld-arm/non-contiguous-arm7.err | 3 +--
.../non-contiguous-merged-sections.d | 9 ++++++++
.../non-contiguous-merged-sections.ld | 18 +++++++++++++++
.../non-contiguous-merged-sections.s | 7 ++++++
ld/testsuite/ld-powerpc/powerpc.exp | 1 +
7 files changed, 51 insertions(+), 11 deletions(-)
create mode 100644 ld/testsuite/ld-powerpc/non-contiguous-merged-sections.d
create mode 100644 ld/testsuite/ld-powerpc/non-contiguous-merged-sections.ld
create mode 100644 ld/testsuite/ld-powerpc/non-contiguous-merged-sections.s
--
2.34.1
@@ -5506,7 +5506,7 @@ size_input_section
"the linker-created stubs section `%pA'.\n"),
i->output_section, i);
- if (i->rawsize && i->rawsize != i->size)
+ if (i->flags & SEC_RELOC && i->rawsize && i->rawsize != i->size)
einfo (_("%F%P: Relaxation not supported with "
"--enable-non-contiguous-regions (section `%pA' "
"would overflow `%pA' after it changed size).\n"),
@@ -8094,8 +8094,9 @@ lang_propagate_lma_regions (void)
}
static void
-warn_non_contiguous_discards (void)
+lang_check_non_contiguous_discards (void)
{
+ unsigned long discard = 0;
LANG_FOR_EACH_INPUT_STATEMENT (file)
{
if ((file->the_bfd->flags & (BFD_LINKER_CREATED | DYNAMIC)) != 0
@@ -8104,11 +8105,16 @@ warn_non_contiguous_discards (void)
for (asection *s = file->the_bfd->sections; s != NULL; s = s->next)
if (s->output_section == NULL
- && (s->flags & SEC_LINKER_CREATED) == 0)
- einfo (_("%P: warning: --enable-non-contiguous-regions "
+ && (s->flags & SEC_LINKER_CREATED) == 0) {
+ einfo (_("%P: error: --enable-non-contiguous-regions "
"discards section `%pA' from `%pB'\n"),
s, file->the_bfd);
+ discard += s->size;
+ }
}
+ if (discard > 0)
+ einfo ("%F%P: error: Total discarded sections size is %lu bytes\n",
+ discard);
}
static void
@@ -8436,6 +8442,10 @@ lang_process (void)
/* Size up the sections. */
lang_size_sections (NULL, !RELAXATION_ENABLED);
+ /* Check if has no discarded sections. */
+ if (link_info.non_contiguous_regions)
+ lang_check_non_contiguous_discards ();
+
/* See if anything special should be done now we know how big
everything is. This is where relaxation is done. */
ldemul_after_allocation ();
@@ -8459,10 +8469,6 @@ lang_process (void)
if (command_line.check_section_addresses)
lang_check_section_addresses ();
- if (link_info.non_contiguous_regions
- && link_info.non_contiguous_regions_warnings)
- warn_non_contiguous_discards ();
-
/* Check any required symbols are known. */
ldlang_check_require_defined_symbols ();
@@ -1,4 +1,4 @@
#name: non-contiguous-arm
#source: non-contiguous-arm.s
#ld: --enable-non-contiguous-regions -T non-contiguous-arm.ld
-# error: .*Could not assign .?\.code\.4.? to an output section. Retry without --enable-non-contiguous-regions\.
+#error_output: non-contiguous-arm.err
@@ -1,5 +1,4 @@
.* may change behaviour for section .?\.bss.? from .*
.* may change behaviour for section .?\.bss\.MY_BUF.? from .*
.* discards section .?\.bss\.MY_BUF.? from .*
-.* unresolvable R_ARM_ABS32 relocation against symbol .?MY_BUF.?
-.* final link failed
+.* Total discarded sections size is [0-9]+ bytes
new file mode 100644
@@ -0,0 +1,9 @@
+#name: non-contiguous-merged-sections
+#source: non-contiguous-merged-sections.s
+#ld: --enable-non-contiguous-regions -T non-contiguous-merged-sections.ld
+#readelf: -l --wide
+
+#...
+ +LOAD +0x[0-9a-f]+ +0x[0-9a-f]+ +0x[0-9a-f]+ 0x00012 0x00012 .*
+#...
+ +00 +\.rodata_ram2
new file mode 100644
@@ -0,0 +1,18 @@
+MEMORY
+{
+ RAM1 (xrw) : ORIGIN = 0x10000000, LENGTH = 4b
+ RAM2 (xrw) : ORIGIN = 0x20000000, LENGTH = 1K
+}
+
+SECTIONS
+{
+ .rodata_ram1 :
+ {
+ *(.rodata) *(.rodata*);
+ } >RAM1
+
+ .rodata_ram2 :
+ {
+ *(.rodata) *(.rodata*);
+ } >RAM2
+}
new file mode 100644
@@ -0,0 +1,7 @@
+ .file "<artificial>"
+ .section .rodata.str1.8,"aMS",@progbits,1
+.LC0:
+ .string "string_1"
+ .section .rodata.str2.8,"aMS",@progbits,1
+.LC1:
+ .string "string_2"
@@ -519,6 +519,7 @@ run_dump_test "ppc476-shared"
run_dump_test "ppc476-shared2"
run_dump_test "non-contiguous-powerpc"
+run_dump_test "non-contiguous-merged-sections"
run_dump_test "tprel32"
run_dump_test "tprelbad"