Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@rui314
Created February 11, 2019 22:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rui314/f3cd508b6cbbde763fc13bc6190d7505 to your computer and use it in GitHub Desktop.
Save rui314/f3cd508b6cbbde763fc13bc6190d7505 to your computer and use it in GitHub Desktop.
diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp
index c3e5b2f4878a..2f0b5df965be 100644
--- a/lld/ELF/InputFiles.cpp
+++ b/lld/ELF/InputFiles.cpp
@@ -239,6 +239,7 @@ ELFFileBase<ELFT>::ELFFileBase(Kind K, MemoryBufferRef MB) : InputFile(K, MB) {
EMachine = getObj().getHeader()->e_machine;
OSABI = getObj().getHeader()->e_ident[llvm::ELF::EI_OSABI];
+ ABIVersion = getObj().getHeader()->e_ident[llvm::ELF::EI_ABIVERSION];
}
template <class ELFT>
diff --git a/lld/ELF/InputFiles.h b/lld/ELF/InputFiles.h
index 07f85e89b7b4..7b4f4e6e27b6 100644
--- a/lld/ELF/InputFiles.h
+++ b/lld/ELF/InputFiles.h
@@ -103,6 +103,7 @@ public:
ELFKind EKind = ELFNoneKind;
uint16_t EMachine = llvm::ELF::EM_NONE;
uint8_t OSABI = 0;
+ uint8_t ABIVersion = 0;
// Cache for toString(). Only toString() should use this member.
mutable std::string ToStringCache;
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index 6465a619d061..35006a729481 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -2382,9 +2382,21 @@ static uint16_t getELFType() {
static uint8_t getAbiVersion() {
// MIPS non-PIC executable gets ABI version 1.
- if (Config->EMachine == EM_MIPS && getELFType() == ET_EXEC &&
- (Config->EFlags & (EF_MIPS_PIC | EF_MIPS_CPIC)) == EF_MIPS_CPIC)
- return 1;
+ if (Config->EMachine == EM_MIPS) {
+ if (getELFType() == ET_EXEC &&
+ (Config->EFlags & (EF_MIPS_PIC | EF_MIPS_CPIC)) == EF_MIPS_CPIC)
+ return 1;
+ return 0;
+ }
+
+ if (Config->EMachine == EM_AMDGPU) {
+ uint8_t Ver = ObjectFiles[0]->ABIVersion;
+ for (InputFile *File : makeArrayRef(ObjectFiles).slice(1))
+ if (File->ABIVersion != Ver)
+ error("incompatible ABI version: " + toString(File));
+ return Ver;
+ }
+
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment