aboutsummaryrefslogtreecommitdiff
path: root/ld
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2022-12-21 16:06:55 +1030
committerAlan Modra <amodra@gmail.com>2022-12-21 17:56:27 +1030
commitc63d4862812c79d81b6423a847c9a288e49574a5 (patch)
treec1a11303d42291b740c736c3c4989f00ee69adcc /ld
parent8f2c64de86bc3d7556121fe296dd679000283931 (diff)
downloadgdb-c63d4862812c79d81b6423a847c9a288e49574a5.zip
gdb-c63d4862812c79d81b6423a847c9a288e49574a5.tar.gz
gdb-c63d4862812c79d81b6423a847c9a288e49574a5.tar.bz2
enable-non-contiguous-regions warnings
The warning about discarded sections in elf_link_input_bfd doesn't belong there since the code is dealing with symbols. Multiple symbols in a discarded section will result in multiple identical warnings about the section. Move the warning to a new function in ldlang.c. The patch also tidies the warning quoting of section and file names, consistently using `%pA' and `%pB'. I'm no stickler for one style of section and file name quoting, but they ought to be consistent within a warning, eg. see the first one fixed in ldlang.c, and when a warning is emitted for multiple targets they all ought to use exactly the same format string to reduce translation work. elf64-ppc.c loses the build_one_stub errors since we won't get there before hitting the fatal errors in size_one_stub. bfd/ * elflink.c (elf_link_input_bfd): Don't warn here about discarded sections. * elf32-arm.c (arm_build_one_stub): Use consistent style in --enable-non-contiguous-regions error. * elf32-csky.c (csky_build_one_stub): Likewise. * elf32-hppa.c (hppa_build_one_stub): Likewise. * elf32-m68hc11.c (m68hc11_elf_build_one_stub): Likewise. * elf32-m68hc12.c (m68hc12_elf_build_one_stub): Likewise. * elf32-metag.c (metag_build_one_stub): Likewise. * elf32-nios2.c (nios2_build_one_stub): Likewise. * elfnn-aarch64.c (aarch64_build_one_stub): Likewise. * xcofflink.c (xcoff_build_one_stub): Likewise. * elf64-ppc.c (ppc_size_one_stub): Likewise. (ppc_build_one_stub): Delete dead code. ld/ * ldlang.c (lang_add_section): Use consistent style in --enable-non-contiguous-regions warnings. (size_input_section): Likewise. (warn_non_contiguous_discards): New function. (lang_process): Call it. * testsuite/ld-arm/non-contiguous-arm.d: Update. * testsuite/ld-arm/non-contiguous-arm4.d: Update. * testsuite/ld-arm/non-contiguous-arm7.d: Add --enable-non-contiguous-regions-warnings. * testsuite/ld-arm/non-contiguous-arm7.err: New. * testsuite/ld-powerpc/non-contiguous-powerpc.d: Update. * testsuite/ld-powerpc/non-contiguous-powerpc64.d: Update.
Diffstat (limited to 'ld')
-rw-r--r--ld/ldlang.c38
-rw-r--r--ld/testsuite/ld-arm/non-contiguous-arm.d2
-rw-r--r--ld/testsuite/ld-arm/non-contiguous-arm4.d2
-rw-r--r--ld/testsuite/ld-arm/non-contiguous-arm7.d4
-rw-r--r--ld/testsuite/ld-arm/non-contiguous-arm7.err4
-rw-r--r--ld/testsuite/ld-powerpc/non-contiguous-powerpc.d2
-rw-r--r--ld/testsuite/ld-powerpc/non-contiguous-powerpc64.d2
7 files changed, 40 insertions, 14 deletions
diff --git a/ld/ldlang.c b/ld/ldlang.c
index 7829f86..315b916 100644
--- a/ld/ldlang.c
+++ b/ld/ldlang.c
@@ -2539,7 +2539,7 @@ lang_add_section (lang_statement_list_type *ptr,
}
else if (link_info.non_contiguous_regions_warnings)
einfo (_("%P:%pS: warning: --enable-non-contiguous-regions makes "
- "section `%pA' from '%pB' match /DISCARD/ clause.\n"),
+ "section `%pA' from `%pB' match /DISCARD/ clause.\n"),
NULL, section, section->owner);
return;
@@ -2572,7 +2572,7 @@ lang_add_section (lang_statement_list_type *ptr,
if (link_info.non_contiguous_regions_warnings && output->bfd_section)
einfo (_("%P:%pS: warning: --enable-non-contiguous-regions may "
- "change behaviour for section `%pA' from '%pB' (assigned to "
+ "change behaviour for section `%pA' from `%pB' (assigned to "
"%pA, but additional match: %pA)\n"),
NULL, section, section->owner, section->output_section,
output->bfd_section);
@@ -5252,15 +5252,15 @@ size_input_section
if (dot + TO_ADDR (i->size) > end)
{
if (i->flags & SEC_LINKER_CREATED)
- einfo (_("%F%P: Output section '%s' not large enough for the "
- "linker-created stubs section '%s'.\n"),
- i->output_section->name, i->name);
+ einfo (_("%F%P: Output section `%pA' not large enough for "
+ "the linker-created stubs section `%pA'.\n"),
+ i->output_section, i);
if (i->rawsize && i->rawsize != i->size)
einfo (_("%F%P: Relaxation not supported with "
- "--enable-non-contiguous-regions (section '%s' "
- "would overflow '%s' after it changed size).\n"),
- i->name, i->output_section->name);
+ "--enable-non-contiguous-regions (section `%pA' "
+ "would overflow `%pA' after it changed size).\n"),
+ i, i->output_section);
*removed = 1;
dot = end;
@@ -7851,6 +7851,24 @@ lang_propagate_lma_regions (void)
}
static void
+warn_non_contiguous_discards (void)
+{
+ LANG_FOR_EACH_INPUT_STATEMENT (file)
+ {
+ if ((file->the_bfd->flags & (BFD_LINKER_CREATED | DYNAMIC)) != 0
+ || file->flags.just_syms)
+ continue;
+
+ 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 "
+ "discards section `%pA' from `%pB'\n"),
+ s, file->the_bfd);
+ }
+}
+
+static void
reset_one_wild (lang_statement_union_type *statement)
{
if (statement->header.type == lang_wild_statement_enum)
@@ -8191,6 +8209,10 @@ 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 ();
diff --git a/ld/testsuite/ld-arm/non-contiguous-arm.d b/ld/testsuite/ld-arm/non-contiguous-arm.d
index d0e5fab..3479778 100644
--- a/ld/testsuite/ld-arm/non-contiguous-arm.d
+++ b/ld/testsuite/ld-arm/non-contiguous-arm.d
@@ -1,4 +1,4 @@
#name: non-contiguous-arm
#source: non-contiguous-arm.s
#ld: --enable-non-contiguous-regions -T non-contiguous-arm.ld
-# error: \A.*Could not assign '.code.4' to an output section. Retry without --enable-non-contiguous-regions.*\Z
+# error: .*Could not assign .?\.code\.4.? to an output section. Retry without --enable-non-contiguous-regions\.
diff --git a/ld/testsuite/ld-arm/non-contiguous-arm4.d b/ld/testsuite/ld-arm/non-contiguous-arm4.d
index a55e8d6..a8e9d66 100644
--- a/ld/testsuite/ld-arm/non-contiguous-arm4.d
+++ b/ld/testsuite/ld-arm/non-contiguous-arm4.d
@@ -1,4 +1,4 @@
#name: non-contiguous-arm4
#source: non-contiguous-arm.s
#ld: --enable-non-contiguous-regions -T non-contiguous-arm4.ld
-# error: \A.*Output section '.ramu' not large enough for the linker-created stubs section '.code.3.__stub'.*\Z
+# error: .*Output section .?\.ramu.? not large enough for the linker-created stubs section .?\.code\.3\.__stub.\.?
diff --git a/ld/testsuite/ld-arm/non-contiguous-arm7.d b/ld/testsuite/ld-arm/non-contiguous-arm7.d
index b8f08d4..94e9757 100644
--- a/ld/testsuite/ld-arm/non-contiguous-arm7.d
+++ b/ld/testsuite/ld-arm/non-contiguous-arm7.d
@@ -1,4 +1,4 @@
#name: non-contiguous-arm7
#source: non-contiguous-arm7.s
-#ld: --enable-non-contiguous-regions -T non-contiguous-arm7.ld
-#error: \A.*unresolvable R_ARM_ABS32 relocation against symbol .MY_BUF..*\Z
+#ld: --enable-non-contiguous-regions --enable-non-contiguous-regions-warnings -T non-contiguous-arm7.ld
+#error_output: non-contiguous-arm7.err
diff --git a/ld/testsuite/ld-arm/non-contiguous-arm7.err b/ld/testsuite/ld-arm/non-contiguous-arm7.err
new file mode 100644
index 0000000..3185ef5
--- /dev/null
+++ b/ld/testsuite/ld-arm/non-contiguous-arm7.err
@@ -0,0 +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.?
diff --git a/ld/testsuite/ld-powerpc/non-contiguous-powerpc.d b/ld/testsuite/ld-powerpc/non-contiguous-powerpc.d
index c0618db..ea41e0d 100644
--- a/ld/testsuite/ld-powerpc/non-contiguous-powerpc.d
+++ b/ld/testsuite/ld-powerpc/non-contiguous-powerpc.d
@@ -1,5 +1,5 @@
#name: non-contiguous-powerpc
#source: non-contiguous-powerpc.s
#ld: --enable-non-contiguous-regions -T non-contiguous-powerpc.ld
-#error: \A.*Relaxation not supported with --enable-non-contiguous-regions.*
+#error: .*Relaxation not supported with --enable-non-contiguous-regions.*
#skip: powerpc64*-*
diff --git a/ld/testsuite/ld-powerpc/non-contiguous-powerpc64.d b/ld/testsuite/ld-powerpc/non-contiguous-powerpc64.d
index ff0e3fc..9f903bb 100644
--- a/ld/testsuite/ld-powerpc/non-contiguous-powerpc64.d
+++ b/ld/testsuite/ld-powerpc/non-contiguous-powerpc64.d
@@ -2,4 +2,4 @@
#source: non-contiguous-powerpc.s
#as: -a64
#ld: -melf64ppc --enable-non-contiguous-regions -T non-contiguous-powerpc.ld
-#error: .*Could not assign group.*
+#error: .*Could not assign .?\.text\.one\.stub.? to an output section\. Retry without --enable-non-contiguous-regions\.