[PATCH] D153335: [ELFAttributeParser] Skip unknown vendor subsections.

Simon Tatham via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 20 06:16:52 PDT 2023


simon_tatham created this revision.
simon_tatham added reviewers: HsiangKai, zixuan-wu, jozefl, MaskRay, peter.smith.
Herald added subscribers: hiraditya, kristof.beyls, emaste.
Herald added a project: All.
simon_tatham requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

An .ARM.attributes section is divided into subsections, each labelled
with a vendor name. There is one standardised vendor name, which must
be used for all attributes that affect compatibility. Subsections
labelled with other vendor names can be used for optimisation
purposes, but it has to be safe for an object file consumer to ignore
them if it doesn't recognise the vendor name.

LLD currently terminates parsing of the whole attributes section as
soon as it encounters a subsection with a vendor name it doesn't
recognise (which is anything other than the standard one). This can
prevent it from detecting compatibility issues, if a standard
subsection followed the vendor-specific one.

This patch modifies the attribute parser so that unrecognised vendor
subsections are silently skipped, and the subsections beyond them are
still processed.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153335

Files:
  lld/test/ELF/Inputs/arm-vfp-arg-vfp-vendor.yaml
  lld/test/ELF/arm-tag-vfp-args-errs.s
  llvm/lib/Support/ELFAttributeParser.cpp


Index: llvm/lib/Support/ELFAttributeParser.cpp
===================================================================
--- llvm/lib/Support/ELFAttributeParser.cpp
+++ llvm/lib/Support/ELFAttributeParser.cpp
@@ -127,10 +127,14 @@
     sw->printString("Vendor", vendorName);
   }
 
-  // Ignore unrecognized vendor-name.
-  if (vendorName.lower() != vendor)
-    return createStringError(errc::invalid_argument,
-                             "unrecognized vendor-name: " + vendorName);
+  // Handle a subsection with an unrecognized vendor-name by skipping
+  // over it to the next subsection. ADDENDA32 in the Arm ABI defines
+  // that vendor attribute sections must not affect compatibility, so
+  // this should always be safe.
+  if (vendorName.lower() != vendor) {
+    cursor.seek(end);
+    return Error::success();
+  }
 
   while (cursor.tell() < end) {
     /// Tag_File | Tag_Section | Tag_Symbol   uleb128:byte-size
Index: lld/test/ELF/arm-tag-vfp-args-errs.s
===================================================================
--- lld/test/ELF/arm-tag-vfp-args-errs.s
+++ lld/test/ELF/arm-tag-vfp-args-errs.s
@@ -1,9 +1,11 @@
 // REQUIRES:arm
 // RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %S/Inputs/arm-vfp-arg-base.s -o %tbase.o
 // RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %S/Inputs/arm-vfp-arg-vfp.s -o %tvfp.o
+// RUN: yaml2obj %S/Inputs/arm-vfp-arg-vfp-vendor.yaml -o %tvfpvendor.o
 // RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %S/Inputs/arm-vfp-arg-toolchain.s -o %ttoolchain.o
 // RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t.o
 // RUN: not ld.lld %t.o %tbase.o %tvfp.o -o%t 2>&1 | FileCheck %s
+// RUN: not ld.lld %t.o %tbase.o %tvfpvendor.o -o%t 2>&1 | FileCheck %s
 // RUN: not ld.lld %t.o %tbase.o %ttoolchain.o -o%t 2>&1 | FileCheck %s
 // RUN: not ld.lld %t.o %tvfp.o %tbase.o -o%t 2>&1 | FileCheck %s
 // RUN: not ld.lld %t.o %tvfp.o %ttoolchain.o -o%t 2>&1 | FileCheck %s
Index: lld/test/ELF/Inputs/arm-vfp-arg-vfp-vendor.yaml
===================================================================
--- /dev/null
+++ lld/test/ELF/Inputs/arm-vfp-arg-vfp-vendor.yaml
@@ -0,0 +1,46 @@
+# Variant form of the object compiled from arm-vfp-arg-vfp.s which
+# adds a vendor attribute subsection in front of the "aeabi" one. LLD
+# ought to skip over it and still parse the "aeabi" subsection beyond
+# it.
+#
+# This file was generated by building arm-vfp-arg-vfp.s, running
+# yaml2obj over it, and manually inserting the hex string
+# 2000000053686F756C64426549676E6F72656400FFFFFFFFFFFFFFFFFFFFFFFF
+# after the initial version byte of the attributes section, which
+# unpacks as a 32-bit length word, the zero-terminated vendor name
+# string "ShouldBeIgnored", and dummy data that's all FFs (since the
+# interior of a vendor subsection is not required to adhere to any
+# standard format).
+
+--- !ELF
+FileHeader:
+  Class:           ELFCLASS32
+  Data:            ELFDATA2LSB
+  Type:            ET_REL
+  Machine:         EM_ARM
+  Flags:           [ EF_ARM_EABI_VER5 ]
+  SectionHeaderStringTable: .strtab
+Sections:
+  - Name:            .text
+    Type:            SHT_PROGBITS
+    Flags:           [ SHF_ALLOC, SHF_EXECINSTR ]
+    AddressAlign:    0x4
+    Content:         1EFF2FE1
+  - Name:            .ARM.attributes
+    Type:            SHT_ARM_ATTRIBUTES
+    AddressAlign:    0x1
+    Content:         412000000053686F756C64426549676E6F72656400FFFFFFFFFFFFFFFFFFFFFFFF30000000616561626900012600000005372D4100060A0741080109021204140115011703180119011A021C011E062201
+  - Type:            SectionHeaderTable
+    Sections:
+      - Name:            .strtab
+      - Name:            .text
+      - Name:            .ARM.attributes
+      - Name:            .symtab
+Symbols:
+  - Name:            '$a.0'
+    Section:         .text
+  - Name:            f1
+    Type:            STT_FUNC
+    Section:         .text
+    Binding:         STB_GLOBAL
+...


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D153335.532885.patch
Type: text/x-patch
Size: 3971 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230620/3d50185f/attachment.bin>


More information about the llvm-commits mailing list