]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
ARC e_flags vs. objcopy
authorAlan Modra <amodra@gmail.com>
Tue, 16 Apr 2024 22:36:05 +0000 (08:06 +0930)
committerAlan Modra <amodra@gmail.com>
Tue, 16 Apr 2024 23:55:15 +0000 (09:25 +0930)
While the patch that Nick reverted in commit 3f6a060c7543 was in the
source, "FAIL: objcopy executable (pr25662)" was seen on ARC.  The
failure was triggered by the .ARC.attributes section being removed by
the linker script.  When a file lacking this section is copied by
objcopy, e_flags from the input is copied to the output (in this case
the value 0x406), but arc_elf_final_write_processing then logical-ors
in 0x300 when Tag_ARC_ABI_osver is not found.

* elf32-arc.c (arc_elf_final_write_processing): Don't ignore
existing e_flags for objcopy.

bfd/elf32-arc.c

index 7e94373773b809175e590384f1f49a63e75aa4ee..bd182996654ce4df8b2c1c925198fc1d4a04c7bc 100644 (file)
@@ -1045,9 +1045,6 @@ static bool
 arc_elf_final_write_processing (bfd *abfd)
 {
   unsigned long emf;
-  int osver = bfd_elf_get_obj_attr_int (abfd, OBJ_ATTR_PROC,
-                                       Tag_ARC_ABI_osver);
-  flagword e_flags = elf_elfheader (abfd)->e_flags & ~EF_ARC_OSABI_MSK;
 
   switch (bfd_get_mach (abfd))
     {
@@ -1062,12 +1059,15 @@ arc_elf_final_write_processing (bfd *abfd)
   elf_elfheader (abfd)->e_machine = emf;
 
   /* Record whatever is the current syscall ABI version.  */
+  int osver = bfd_elf_get_obj_attr_int (abfd, OBJ_ATTR_PROC,
+                                       Tag_ARC_ABI_osver);
+  flagword e_flags = elf_elfheader (abfd)->e_flags;
   if (osver)
-    e_flags |= ((osver & 0x0f) << 8);
-  else
+    e_flags = (e_flags & ~EF_ARC_OSABI_MSK) | ((osver & 0x0f) << 8);
+  else if ((e_flags & EF_ARC_OSABI_MSK) == 0)
     e_flags |= E_ARC_OSABI_V3;
 
-  elf_elfheader (abfd)->e_flags |= e_flags;
+  elf_elfheader (abfd)->e_flags = e_flags;
   return _bfd_elf_final_write_processing (abfd);
 }