[lld] r325890 - [ELF][MIPS] Set EI_ABIVERSION flag accordingly to MIPS ABIs requirement
Simon Atanasyan via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 23 03:28:57 PST 2018
Author: atanasyan
Date: Fri Feb 23 03:28:57 2018
New Revision: 325890
URL: http://llvm.org/viewvc/llvm-project?rev=325890&view=rev
Log:
[ELF][MIPS] Set EI_ABIVERSION flag accordingly to MIPS ABIs requirement
MIPS ABIs require that if an executable file uses non-PIC model, the
EI_ABIVERSION entry in the ELF header should be incremented from 0 to 1.
That allows obsoleted / limited dynamic linkers refuse to link them.
Added:
lld/trunk/test/ELF/mips-elf-abi.s
Modified:
lld/trunk/ELF/Writer.cpp
lld/trunk/test/ELF/basic-mips.s
lld/trunk/test/ELF/emulation.s
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=325890&r1=325889&r2=325890&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Fri Feb 23 03:28:57 2018
@@ -2069,6 +2069,16 @@ static uint16_t getELFType() {
return ET_EXEC;
}
+static uint8_t getAbiVersion() {
+ if (Config->EMachine == EM_MIPS) {
+ // Increment the ABI version for non-PIC executable files.
+ if (getELFType() == ET_EXEC &&
+ (Config->EFlags & (EF_MIPS_PIC | EF_MIPS_CPIC)) == EF_MIPS_CPIC)
+ return 1;
+ }
+ return 0;
+}
+
template <class ELFT> void Writer<ELFT>::writeHeader() {
uint8_t *Buf = Buffer->getBufferStart();
memcpy(Buf, "\177ELF", 4);
@@ -2079,6 +2089,7 @@ template <class ELFT> void Writer<ELFT>:
EHdr->e_ident[EI_DATA] = Config->IsLE ? ELFDATA2LSB : ELFDATA2MSB;
EHdr->e_ident[EI_VERSION] = EV_CURRENT;
EHdr->e_ident[EI_OSABI] = Config->OSABI;
+ EHdr->e_ident[EI_ABIVERSION] = getAbiVersion();
EHdr->e_type = getELFType();
EHdr->e_machine = Config->EMachine;
EHdr->e_version = EV_CURRENT;
Modified: lld/trunk/test/ELF/basic-mips.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/basic-mips.s?rev=325890&r1=325889&r2=325890&view=diff
==============================================================================
--- lld/trunk/test/ELF/basic-mips.s (original)
+++ lld/trunk/test/ELF/basic-mips.s Fri Feb 23 03:28:57 2018
@@ -19,7 +19,7 @@ __start:
# CHECK-NEXT: DataEncoding: LittleEndian (0x1)
# CHECK-NEXT: FileVersion: 1
# CHECK-NEXT: OS/ABI: SystemV (0x0)
-# CHECK-NEXT: ABIVersion: 0
+# CHECK-NEXT: ABIVersion: 1
# CHECK-NEXT: Unused: (00 00 00 00 00 00 00)
# CHECK-NEXT: }
# CHECK-NEXT: Type: Executable (0x2)
Modified: lld/trunk/test/ELF/emulation.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/emulation.s?rev=325890&r1=325889&r2=325890&view=diff
==============================================================================
--- lld/trunk/test/ELF/emulation.s (original)
+++ lld/trunk/test/ELF/emulation.s Fri Feb 23 03:28:57 2018
@@ -230,7 +230,7 @@
# MIPS-NEXT: DataEncoding: BigEndian (0x2)
# MIPS-NEXT: FileVersion: 1
# MIPS-NEXT: OS/ABI: SystemV (0x0)
-# MIPS-NEXT: ABIVersion: 0
+# MIPS-NEXT: ABIVersion: 1
# MIPS-NEXT: Unused: (00 00 00 00 00 00 00)
# MIPS-NEXT: }
# MIPS-NEXT: Type: Executable (0x2)
@@ -259,7 +259,7 @@
# MIPSEL-NEXT: DataEncoding: LittleEndian (0x1)
# MIPSEL-NEXT: FileVersion: 1
# MIPSEL-NEXT: OS/ABI: SystemV (0x0)
-# MIPSEL-NEXT: ABIVersion: 0
+# MIPSEL-NEXT: ABIVersion: 1
# MIPSEL-NEXT: Unused: (00 00 00 00 00 00 00)
# MIPSEL-NEXT: }
# MIPSEL-NEXT: Type: Executable (0x2)
Added: lld/trunk/test/ELF/mips-elf-abi.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/mips-elf-abi.s?rev=325890&view=auto
==============================================================================
--- lld/trunk/test/ELF/mips-elf-abi.s (added)
+++ lld/trunk/test/ELF/mips-elf-abi.s Fri Feb 23 03:28:57 2018
@@ -0,0 +1,23 @@
+# Check EI_ABIVERSION flags
+
+# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s -o %t.o
+# RUN: ld.lld -shared -o %t.so %t.o
+# RUN: llvm-readobj -h %t.so | FileCheck -check-prefix=DSO %s
+# RUN: ld.lld -o %t.exe %t.o
+# RUN: llvm-readobj -h %t.exe | FileCheck -check-prefix=EXE %s
+# RUN: ld.lld -pie -o %t.pie %t.o
+# RUN: llvm-readobj -h %t.pie | FileCheck -check-prefix=PIE %s
+# RUN: ld.lld -r -o %t.rel %t.o
+# RUN: llvm-readobj -h %t.rel | FileCheck -check-prefix=REL %s
+
+# REQUIRES: mips
+
+# DSO: ABIVersion: 0
+# EXE: ABIVersion: 1
+# PIE: ABIVersion: 0
+# REL: ABIVersion: 0
+
+ .global __start
+ .text
+__start:
+ nop
More information about the llvm-commits
mailing list