[3/3] ld: warn when duplicated QNX stack note are detected

Message ID 20231013080248.219837-3-chigot@adacore.com
State New
Headers
Series [1/3] ld: allow update of existing QNX stack note |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_check--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_binutils_check--master-arm fail Patch failed to apply
linaro-tcwg-bot/tcwg_binutils_build--master-arm fail Patch failed to apply
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 fail Patch failed to apply

Commit Message

Clément Chigot Oct. 13, 2023, 8:02 a.m. UTC
  This warning is triggered only when a stack parameter is given to
the linker.

ld/ChangeLog:

        * emultempl/nto.em: Add warning when several QNX .note are
        detected.
---
 ld/emultempl/nto.em | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)
  

Comments

Nick Clifton Oct. 13, 2023, 2:07 p.m. UTC | #1
Hi Clément,

>          * emultempl/nto.em: Add warning when several QNX .note are
>          detected.

Approved - please apply.

Cheers
   Nick
  

Patch

diff --git a/ld/emultempl/nto.em b/ld/emultempl/nto.em
index b1a61338412..f4c76f18fc2 100644
--- a/ld/emultempl/nto.em
+++ b/ld/emultempl/nto.em
@@ -86,6 +86,7 @@  nto_lookup_QNX_note_section(int type)
 {
   asection *stack_note_sec = NULL;
   bfd *abfd;
+  bool duplicated_notes_detected = false;
   for (abfd = link_info.input_bfds; abfd != NULL; abfd = abfd->link.next)
     {
       Elf_External_Note *e_note;
@@ -106,10 +107,23 @@  nto_lookup_QNX_note_section(int type)
       e_note = (Elf_External_Note *) sec->contents;
       if (! strcmp("QNX", e_note->name) && *e_note->type == type)
 	{
-	  stack_note_sec = sec;
-	  /* Allow modification of this .note content.  */
-	  stack_note_sec->flags |= SEC_IN_MEMORY;
-	  break;
+	  if (stack_note_sec)
+	    {
+	      if (!duplicated_notes_detected)
+		{
+		  einfo (_("%P: %pB: warning: duplicated QNX stack .note detected\n"),
+			 stack_note_sec->owner);
+		  duplicated_notes_detected = true;
+		}
+	      einfo (_("%P: %pB: warning: duplicated QNX stack .note detected\n"),
+		     sec->owner);
+	    }
+	  else
+	    {
+	      stack_note_sec = sec;
+	      /* Allow modification of this .note content.  */
+	      stack_note_sec->flags |= SEC_IN_MEMORY;
+	    }
 	}
     }