public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v2] bfd: Discard region regardless of warning flag
@ 2022-12-19 18:34 Torbjörn SVENSSON
  2022-12-19 22:59 ` Alan Modra
  0 siblings, 1 reply; 3+ messages in thread
From: Torbjörn SVENSSON @ 2022-12-19 18:34 UTC (permalink / raw)
  To: binutils; +Cc: christophe.lyon, Torbjörn SVENSSON, Yvan ROUX

v1 -> v2:
Added testcase

Ok for trunk?



I have commit access for GDB. Do I still need someone to push this for
me or do I automatically have write access to the complete binutils
repository and just need the approval to push it myself?

---

The discard of the region should be performed regardless if the warning
for the discard is enabled or not.
Without this patch, ld would segfault in bfd_section_removed_from_list,
called in the if-statement right after this block, as the argument
isec->output_section can be NULL.

Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
Co-Authored-By: Yvan ROUX <yan.roux@foss.st.com>
---
 bfd/elflink.c                              | 10 +++----
 ld/testsuite/ld-arm/arm-elf.exp            |  1 +
 ld/testsuite/ld-arm/non-contiguous-arm7.d  |  4 +++
 ld/testsuite/ld-arm/non-contiguous-arm7.ld | 32 ++++++++++++++++++++++
 ld/testsuite/ld-arm/non-contiguous-arm7.s  | 16 +++++++++++
 5 files changed, 58 insertions(+), 5 deletions(-)
 create mode 100644 ld/testsuite/ld-arm/non-contiguous-arm7.d
 create mode 100644 ld/testsuite/ld-arm/non-contiguous-arm7.ld
 create mode 100644 ld/testsuite/ld-arm/non-contiguous-arm7.s

diff --git a/bfd/elflink.c b/bfd/elflink.c
index fc3edef9a05..0368256970b 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -11154,12 +11154,12 @@ elf_link_input_bfd (struct elf_final_link_info *flinfo, bfd *input_bfd)
       if (isym->st_shndx != SHN_UNDEF
 	  && isym->st_shndx < SHN_LORESERVE
 	  && isec->output_section == NULL
-	  && flinfo->info->non_contiguous_regions
-	  && flinfo->info->non_contiguous_regions_warnings)
+	  && flinfo->info->non_contiguous_regions)
 	{
-	  _bfd_error_handler (_("warning: --enable-non-contiguous-regions "
-				"discards section `%s' from '%s'\n"),
-			      isec->name, bfd_get_filename (isec->owner));
+	  if (flinfo->info->non_contiguous_regions_warnings)
+	    _bfd_error_handler (_("warning: --enable-non-contiguous-regions "
+				  "discards section `%s' from '%s'\n"),
+				isec->name, bfd_get_filename (isec->owner));
 	  continue;
 	}
 
diff --git a/ld/testsuite/ld-arm/arm-elf.exp b/ld/testsuite/ld-arm/arm-elf.exp
index e53b9bba723..ce3605d3709 100644
--- a/ld/testsuite/ld-arm/arm-elf.exp
+++ b/ld/testsuite/ld-arm/arm-elf.exp
@@ -1271,6 +1271,7 @@ run_dump_test "non-contiguous-arm3"
 run_dump_test "non-contiguous-arm4"
 run_dump_test "non-contiguous-arm5"
 run_dump_test "non-contiguous-arm6"
+run_dump_test "non-contiguous-arm7"
 
 if { !$is_nacl && [check_shared_lib_support] } {
     run_dump_test "thumb-plt"
diff --git a/ld/testsuite/ld-arm/non-contiguous-arm7.d b/ld/testsuite/ld-arm/non-contiguous-arm7.d
new file mode 100644
index 00000000000..b7621615004
--- /dev/null
+++ b/ld/testsuite/ld-arm/non-contiguous-arm7.d
@@ -0,0 +1,4 @@
+#name: non-contiguous-arm7
+#source: non-contiguous-arm7.s
+#ld: --enable-non-contiguous-regions -T non-contiguous-arm7.ld --gc-sections
+#error: \A.*unresolvable R_ARM_ABS32 relocation against symbol .MY_BUF..*\Z
diff --git a/ld/testsuite/ld-arm/non-contiguous-arm7.ld b/ld/testsuite/ld-arm/non-contiguous-arm7.ld
new file mode 100644
index 00000000000..9934fdfd3a4
--- /dev/null
+++ b/ld/testsuite/ld-arm/non-contiguous-arm7.ld
@@ -0,0 +1,32 @@
+/*
+ The section .bss.MY_BUF won't fit in RAM1 or RAM2
+*/
+
+MEMORY
+{
+  ROM  (rx)    : ORIGIN = 0x8000000,    LENGTH = 10K
+  RAM1 (xrw)   : ORIGIN = 0x10000000,   LENGTH = 64K
+  RAM2 (xrw)   : ORIGIN = 0x20000000,   LENGTH = 96K
+}
+
+SECTIONS
+{
+  .text :
+  {
+    KEEP(*(.text.foo)) ;
+  } >ROM
+
+  .bss :
+  {
+    _sbss = .;
+    *(.bss) *(.bss*) ;
+    _ebss = .;
+  } >RAM1
+
+  .bss_ram2 :
+  {
+    _sbss_ram2 = .;
+    *(.bss) *(.bss*) ;
+    _ebss_ram2 = .;
+  } >RAM2
+}
diff --git a/ld/testsuite/ld-arm/non-contiguous-arm7.s b/ld/testsuite/ld-arm/non-contiguous-arm7.s
new file mode 100644
index 00000000000..be0a407ddc4
--- /dev/null
+++ b/ld/testsuite/ld-arm/non-contiguous-arm7.s
@@ -0,0 +1,16 @@
+  .global MY_BUF
+  .section  .bss.MY_BUF,"aw",%nobits
+  .type	MY_BUF, %object
+  .size	MY_BUF, 102400
+MY_BUF:
+  .space  102400
+
+  .section  .text.foo,"ax",%progbits
+  .global foo
+  .type	foo, %function
+foo:
+  ldr r0, .L3
+  bx lr
+.L3:
+  .word	MY_BUF
+  .size	foo, .-foo
-- 
2.25.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] bfd: Discard region regardless of warning flag
  2022-12-19 18:34 [PATCH v2] bfd: Discard region regardless of warning flag Torbjörn SVENSSON
@ 2022-12-19 22:59 ` Alan Modra
  2022-12-20 10:38   ` Torbjorn SVENSSON
  0 siblings, 1 reply; 3+ messages in thread
From: Alan Modra @ 2022-12-19 22:59 UTC (permalink / raw)
  To: Torbjörn SVENSSON; +Cc: binutils, christophe.lyon, Yvan ROUX

On Mon, Dec 19, 2022 at 07:34:51PM +0100, Torbjörn SVENSSON via Binutils wrote:
> v1 -> v2:
> Added testcase
> 
> Ok for trunk?

This is OK except for a few minor things.

> I have commit access for GDB. Do I still need someone to push this for
> me or do I automatically have write access to the complete binutils
> repository and just need the approval to push it myself?

You should be able to push it.

> The discard of the region should be performed regardless if the warning

This should say "The discard of symbols in..." not "The discard of...".
The code here is handling symbols.

> for the discard is enabled or not.

> +++ b/ld/testsuite/ld-arm/non-contiguous-arm7.d
> @@ -0,0 +1,4 @@
> +#name: non-contiguous-arm7
> +#source: non-contiguous-arm7.s
> +#ld: --enable-non-contiguous-regions -T non-contiguous-arm7.ld --gc-sections

Please remove --gc-sections.  The testcase doesn't need it.

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] bfd: Discard region regardless of warning flag
  2022-12-19 22:59 ` Alan Modra
@ 2022-12-20 10:38   ` Torbjorn SVENSSON
  0 siblings, 0 replies; 3+ messages in thread
From: Torbjorn SVENSSON @ 2022-12-20 10:38 UTC (permalink / raw)
  To: Alan Modra; +Cc: binutils, christophe.lyon, Yvan ROUX



On 2022-12-19 23:59, Alan Modra wrote:
> On Mon, Dec 19, 2022 at 07:34:51PM +0100, Torbjörn SVENSSON via Binutils wrote:
>> v1 -> v2:
>> Added testcase
>>
>> Ok for trunk?
> 
> This is OK except for a few minor things.
> 
>> I have commit access for GDB. Do I still need someone to push this for
>> me or do I automatically have write access to the complete binutils
>> repository and just need the approval to push it myself?
> 
> You should be able to push it.
> 
>> The discard of the region should be performed regardless if the warning
> 
> This should say "The discard of symbols in..." not "The discard of...".
> The code here is handling symbols.
> 
>> for the discard is enabled or not.
> 
>> +++ b/ld/testsuite/ld-arm/non-contiguous-arm7.d
>> @@ -0,0 +1,4 @@
>> +#name: non-contiguous-arm7
>> +#source: non-contiguous-arm7.s
>> +#ld: --enable-non-contiguous-regions -T non-contiguous-arm7.ld --gc-sections
> 
> Please remove --gc-sections.  The testcase doesn't need it.
> 

Pushed with the modifications mentioned above.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-12-20 10:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-19 18:34 [PATCH v2] bfd: Discard region regardless of warning flag Torbjörn SVENSSON
2022-12-19 22:59 ` Alan Modra
2022-12-20 10:38   ` Torbjorn SVENSSON

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).