[PATCH] D27770: [ELF][MIPS] Allow .MIPS.abiflags larger than one Elf_Mips_ABIFlags struct

Alexander Richardson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 19 06:56:23 PST 2016


arichardson updated this revision to Diff 81946.

https://reviews.llvm.org/D27770

Files:
  ELF/SyntheticSections.cpp
  test/ELF/Inputs/mips-concatenated-abiflags.o
  test/ELF/mips-merge-abiflags.s


Index: test/ELF/mips-merge-abiflags.s
===================================================================
--- /dev/null
+++ test/ELF/mips-merge-abiflags.s
@@ -0,0 +1,63 @@
+# Test that lld handles input files with concatenated .MIPS.abiflags sections
+# This happens e.g. with the FreeBSD BFD (BFD 2.17.50 [FreeBSD] 2007-07-03)
+# RUN: llvm-mc -filetype=obj -triple=mips64-unknown-freebsd %s -o %t.o
+# RUN: ld.lld %t.o %p/Inputs/mips-concatenated-abiflags.o -o %t.exe
+# RUN: llvm-readobj -sections -mips-abi-flags %t.exe | FileCheck %s
+# RUN: llvm-readobj -sections -mips-abi-flags \
+# RUN:   %p/Inputs/mips-concatenated-abiflags.o | FileCheck \
+# RUN:   --check-prefix=INPUT-OBJECT %s
+
+# REQUIRES: mips
+        .globl  __start
+__start:
+        nop
+
+# CHECK:      Sections [
+# CHECK:        Section {
+# CHECK:          Index: 1
+# CHECK-NEXT:     Name: .MIPS.abiflags
+# CHECK-NEXT:     Type: SHT_MIPS_ABIFLAGS (0x7000002A)
+# CHECK-NEXT:     Flags [ (0x2)
+# CHECK-NEXT:       SHF_ALLOC (0x2)
+# CHECK-NEXT:     ]
+# CHECK-NEXT:     Address: 0x10190
+# CHECK-NEXT:     Offset: 0x190
+# CHECK-NEXT:     Size: 24
+# CHECK-NEXT:     Link: 0
+# CHECK-NEXT:     Info: 0
+# CHECK-NEXT:     AddressAlignment: 8
+# CHECK-NEXT:     EntrySize: 24
+# CHECK-NEXT:   }
+# CHECK:      MIPS ABI Flags {
+# CHECK-NEXT:   Version: 0
+# CHECK-NEXT:   ISA: MIPS64
+# CHECK-NEXT:   ISA Extension: None (0x0)
+# CHECK-NEXT:   ASEs [ (0x0)
+# CHECK-NEXT:   ]
+# CHECK-NEXT:   FP ABI: Hard float (double precision) (0x1)
+# CHECK-NEXT:   GPR size: 64
+# CHECK-NEXT:   CPR1 size: 64
+# CHECK-NEXT:   CPR2 size: 0
+# CHECK-NEXT:   Flags 1 [ (0x1)
+# CHECK-NEXT:     ODDSPREG (0x1)
+# CHECK-NEXT:   ]
+# CHECK-NEXT:   Flags 2: 0x0
+# CHECK-NEXT: }
+
+# INPUT-OBJECT:      Sections [
+# INPUT-OBJECT:       Section {
+# INPUT-OBJECT:         Index: 3
+# INPUT-OBJECT-NEXT:    Name: .MIPS.abiflags (47)
+# INPUT-OBJECT-NEXT:    Type: SHT_MIPS_ABIFLAGS (0x7000002A)
+# INPUT-OBJECT-NEXT:    Flags [ (0x2)
+# INPUT-OBJECT-NEXT:      SHF_ALLOC (0x2)
+# INPUT-OBJECT-NEXT:    ]
+# INPUT-OBJECT-NEXT:    Address: 0x0
+# INPUT-OBJECT-NEXT:    Offset: 0xA8
+# INPUT-OBJECT-NEXT:    Size: 48
+# INPUT-OBJECT-NEXT:    Link: 0
+# INPUT-OBJECT-NEXT:    Info: 0
+# INPUT-OBJECT-NEXT:    AddressAlignment: 8
+# INPUT-OBJECT-NEXT:    EntrySize: 0
+# INPUT-OBJECT-NEXT:  }
+# INPUT-OBJECT:       The .MIPS.abiflags section has a wrong size.
Index: ELF/SyntheticSections.cpp
===================================================================
--- ELF/SyntheticSections.cpp
+++ ELF/SyntheticSections.cpp
@@ -134,8 +134,13 @@
     Create = true;
 
     std::string Filename = toString(Sec->getFile());
-    if (Sec->Data.size() != sizeof(Elf_Mips_ABIFlags)) {
-      error(Filename + ": invalid size of .MIPS.abiflags section");
+    const auto Size = Sec->Data.size();
+    // Older version of BFD (such as the default FreeBSD linker) concatenate
+    // .MIPS.abiflags instead of merging. To allow for this case (or potential
+    // zero padding) we ignore everything after the first Elf_Mips_ABIFlags
+    if (Size < sizeof(Elf_Mips_ABIFlags)) {
+      error(Filename + ": invalid size of .MIPS.abiflags section: got " +
+            Twine(Size) + " instead of " + Twine(sizeof(Elf_Mips_ABIFlags)));
       return nullptr;
     }
     auto *S = reinterpret_cast<const Elf_Mips_ABIFlags *>(Sec->Data.data());


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27770.81946.patch
Type: text/x-patch
Size: 3381 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161219/a395ba38/attachment.bin>


More information about the llvm-commits mailing list