1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-21 18:22:53 +01:00

[ifs][elfabi] Merge llvm-ifs/elfabi tools

This change merges llvm-elfabi and llvm-ifs tools.

Differential Revision: https://reviews.llvm.org/D100139
This commit is contained in:
Haowei Wu 2021-04-01 20:55:11 -07:00
parent bcce63dd25
commit 5403a31116
66 changed files with 376 additions and 755 deletions

View File

@ -22,7 +22,7 @@ namespace llvm {
class MemoryBuffer;
namespace elfabi {
namespace ifs {
/// Attempt to read a binary ELF file from a MemoryBuffer.
Expected<std::unique_ptr<IFSStub>> readELFFile(MemoryBufferRef Buf);
@ -38,7 +38,7 @@ Expected<std::unique_ptr<IFSStub>> readELFFile(MemoryBufferRef Buf);
Error writeBinaryStub(StringRef FilePath, const IFSStub &Stub,
bool WriteIfChanged = false);
} // end namespace elfabi
} // end namespace ifs
} // end namespace llvm
#endif // LLVM_INTERFACESTUB_ELFOBJHANDLER_H

View File

@ -26,7 +26,7 @@ class raw_ostream;
class Error;
class StringRef;
namespace elfabi {
namespace ifs {
struct IFSStub;
@ -54,7 +54,7 @@ void stripIFSTarget(IFSStub &Stub, bool StripTriple, bool StripArch,
/// Parse llvm triple string into a IFSTarget struct.
IFSTarget parseTriple(StringRef TripleStr);
} // end namespace elfabi
} // end namespace ifs
} // end namespace llvm
#endif // LLVM_INTERFACESTUB_IFSHANDLER_H

View File

@ -20,7 +20,7 @@
#include <vector>
namespace llvm {
namespace elfabi {
namespace ifs {
typedef uint16_t IFSArch;
@ -151,7 +151,7 @@ IFSEndiannessType convertELFEndiannessToIFS(uint8_t Endianness);
///
/// @param SymbolType Binary symbol st_info to extract symbol type from.
IFSSymbolType convertELFSymbolTypeToIFS(uint8_t SymbolType);
} // end namespace elfabi
} // namespace ifs
} // end namespace llvm
#endif // LLVM_INTERFACESTUB_IFSSTUB_H

View File

@ -27,7 +27,7 @@ using namespace llvm::object;
using namespace llvm::ELF;
namespace llvm {
namespace elfabi {
namespace ifs {
// Simple struct to hold relevant .dynamic entries.
struct DynamicEntries {
@ -671,5 +671,5 @@ Error writeBinaryStub(StringRef FilePath, const IFSStub &Stub,
llvm_unreachable("invalid binary output target");
}
} // namespace elfabi
} // end namespace ifs
} // end namespace llvm

View File

@ -17,7 +17,7 @@
#include "llvm/Support/YAMLTraits.h"
using namespace llvm;
using namespace llvm::elfabi;
using namespace llvm::ifs;
LLVM_YAML_IS_SEQUENCE_VECTOR(IFSSymbol)
@ -171,7 +171,7 @@ bool usesTriple(StringRef Buf) {
return true;
}
Expected<std::unique_ptr<IFSStub>> elfabi::readIFSFromBuffer(StringRef Buf) {
Expected<std::unique_ptr<IFSStub>> ifs::readIFSFromBuffer(StringRef Buf) {
yaml::Input YamlIn(Buf);
std::unique_ptr<IFSStubTriple> Stub(new IFSStubTriple());
if (usesTriple(Buf)) {
@ -183,7 +183,7 @@ Expected<std::unique_ptr<IFSStub>> elfabi::readIFSFromBuffer(StringRef Buf) {
return createStringError(Err, "YAML failed reading as IFS");
}
if (Stub->IfsVersion > elfabi::IFSVersionCurrent)
if (Stub->IfsVersion > IFSVersionCurrent)
return make_error<StringError>(
"IFS version " + Stub->IfsVersion.getAsString() + " is unsupported.",
std::make_error_code(std::errc::invalid_argument));
@ -194,7 +194,7 @@ Expected<std::unique_ptr<IFSStub>> elfabi::readIFSFromBuffer(StringRef Buf) {
return std::move(Stub);
}
Error elfabi::writeIFSToOutputStream(raw_ostream &OS, const IFSStub &Stub) {
Error ifs::writeIFSToOutputStream(raw_ostream &OS, const IFSStub &Stub) {
yaml::Output YamlOut(OS, NULL, /*WrapColumn =*/0);
std::unique_ptr<IFSStubTriple> CopyStub(new IFSStubTriple(Stub));
if (Stub.Target.Arch) {
@ -212,10 +212,10 @@ Error elfabi::writeIFSToOutputStream(raw_ostream &OS, const IFSStub &Stub) {
return Error::success();
}
Error elfabi::overrideIFSTarget(IFSStub &Stub, Optional<IFSArch> OverrideArch,
Optional<IFSEndiannessType> OverrideEndianness,
Optional<IFSBitWidthType> OverrideBitWidth,
Optional<std::string> OverrideTriple) {
Error ifs::overrideIFSTarget(IFSStub &Stub, Optional<IFSArch> OverrideArch,
Optional<IFSEndiannessType> OverrideEndianness,
Optional<IFSBitWidthType> OverrideBitWidth,
Optional<std::string> OverrideTriple) {
std::error_code OverrideEC(1, std::generic_category());
if (OverrideArch) {
if (Stub.Target.Arch &&
@ -252,7 +252,7 @@ Error elfabi::overrideIFSTarget(IFSStub &Stub, Optional<IFSArch> OverrideArch,
return Error::success();
}
Error elfabi::validateIFSTarget(IFSStub &Stub, bool ParseTriple) {
Error ifs::validateIFSTarget(IFSStub &Stub, bool ParseTriple) {
std::error_code ValidationEC(1, std::generic_category());
if (Stub.Target.Triple) {
if (Stub.Target.Arch || Stub.Target.BitWidth || Stub.Target.Endianness ||
@ -287,7 +287,7 @@ Error elfabi::validateIFSTarget(IFSStub &Stub, bool ParseTriple) {
return Error::success();
}
IFSTarget elfabi::parseTriple(StringRef TripleStr) {
IFSTarget ifs::parseTriple(StringRef TripleStr) {
Triple IFSTriple(TripleStr);
IFSTarget RetTarget;
// TODO: Implement a Triple Arch enum to e_machine map.
@ -308,8 +308,8 @@ IFSTarget elfabi::parseTriple(StringRef TripleStr) {
return RetTarget;
}
void elfabi::stripIFSTarget(IFSStub &Stub, bool StripTriple, bool StripArch,
bool StripEndianness, bool StripBitWidth) {
void ifs::stripIFSTarget(IFSStub &Stub, bool StripTriple, bool StripArch,
bool StripEndianness, bool StripBitWidth) {
if (StripTriple || StripArch) {
Stub.Target.Arch.reset();
Stub.Target.ArchString.reset();

View File

@ -11,7 +11,7 @@
#include "llvm/Support/Error.h"
using namespace llvm;
using namespace llvm::elfabi;
using namespace llvm::ifs;
IFSStub::IFSStub(IFSStub const &Stub) {
IfsVersion = Stub.IfsVersion;
@ -58,7 +58,7 @@ bool IFSTarget::empty() {
!BitWidth;
}
uint8_t elfabi::convertIFSBitWidthToELF(IFSBitWidthType BitWidth) {
uint8_t ifs::convertIFSBitWidthToELF(IFSBitWidthType BitWidth) {
switch (BitWidth) {
case IFSBitWidthType::IFS32:
return ELF::ELFCLASS32;
@ -69,7 +69,7 @@ uint8_t elfabi::convertIFSBitWidthToELF(IFSBitWidthType BitWidth) {
}
}
uint8_t elfabi::convertIFSEndiannessToELF(IFSEndiannessType Endianness) {
uint8_t ifs::convertIFSEndiannessToELF(IFSEndiannessType Endianness) {
switch (Endianness) {
case IFSEndiannessType::Little:
return ELF::ELFDATA2LSB;
@ -80,7 +80,7 @@ uint8_t elfabi::convertIFSEndiannessToELF(IFSEndiannessType Endianness) {
}
}
uint8_t elfabi::convertIFSSymbolTypeToELF(IFSSymbolType SymbolType) {
uint8_t ifs::convertIFSSymbolTypeToELF(IFSSymbolType SymbolType) {
switch (SymbolType) {
case IFSSymbolType::Object:
return ELF::STT_OBJECT;
@ -94,7 +94,7 @@ uint8_t elfabi::convertIFSSymbolTypeToELF(IFSSymbolType SymbolType) {
}
}
IFSBitWidthType elfabi::convertELFBitWidthToIFS(uint8_t BitWidth) {
IFSBitWidthType ifs::convertELFBitWidthToIFS(uint8_t BitWidth) {
switch (BitWidth) {
case ELF::ELFCLASS32:
return IFSBitWidthType::IFS32;
@ -105,7 +105,7 @@ IFSBitWidthType elfabi::convertELFBitWidthToIFS(uint8_t BitWidth) {
}
}
IFSEndiannessType elfabi::convertELFEndiannessToIFS(uint8_t Endianness) {
IFSEndiannessType ifs::convertELFEndiannessToIFS(uint8_t Endianness) {
switch (Endianness) {
case ELF::ELFDATA2LSB:
return IFSEndiannessType::Little;
@ -116,7 +116,7 @@ IFSEndiannessType elfabi::convertELFEndiannessToIFS(uint8_t Endianness) {
}
}
IFSSymbolType elfabi::convertELFSymbolTypeToIFS(uint8_t SymbolType) {
IFSSymbolType ifs::convertELFSymbolTypeToIFS(uint8_t SymbolType) {
SymbolType = SymbolType & 0xf;
switch (SymbolType) {
case ELF::STT_OBJECT:

View File

@ -77,7 +77,6 @@ set(LLVM_TEST_DEPENDS
dsymutil
llvm-dwarfdump
llvm-dwp
llvm-elfabi
llvm-exegesis
llvm-extract
llvm-gsymutil

View File

@ -1,5 +1,5 @@
# RUN: yaml2obj %s -o %t
# RUN: llvm-elfabi --input-format=ELF --output-format=IFS --output=- --soname=best.so %t | FileCheck %s
# RUN: llvm-ifs --input-format=ELF --output-format=IFS --output=- --soname=best.so %t | FileCheck %s
!ELF
FileHeader:

View File

@ -1,6 +1,6 @@
# RUN: yaml2obj --docnum=1 %s -o %t
# RUN: llvm-elfabi --input-format=ELF --output-format=IFS --output=- %t | FileCheck %s -DTARGET="{ ObjectFormat: ELF, Arch: x86_64, Endianness: little, BitWidth: 64 }"
# RUN: llvm-elfabi --input-format=ELF --output-format=IFS --output=- --hint-ifs-target="x86_64-linux-gnu" %t | FileCheck %s -DTARGET="x86_64-linux-gnu"
# RUN: llvm-ifs --input-format=ELF --output-format=IFS --output=- %t | FileCheck %s -DTARGET="{ ObjectFormat: ELF, Arch: x86_64, Endianness: little, BitWidth: 64 }"
# RUN: llvm-ifs --input-format=ELF --output-format=IFS --output=- --hint-ifs-target="x86_64-linux-gnu" %t | FileCheck %s -DTARGET="x86_64-linux-gnu"
--- !ELF
FileHeader:
@ -52,7 +52,7 @@ ProgramHeaders:
# HINTERR: error: Triple hint does not match the actual [[MSG]]
# RUN: yaml2obj --docnum=1 %s -o %t
# RUN: not llvm-elfabi --input-format=ELF --output-format=IFS --output=%t.tbe --hint-ifs-target="aarch64-linux-gnu" %t 2>&1 | FileCheck %s -DMSG=architecture --check-prefix=HINTERR
# RUN: not llvm-ifs --input-format=ELF --output-format=IFS --output=%t.tbe --hint-ifs-target="aarch64-linux-gnu" %t 2>&1 | FileCheck %s -DMSG=architecture --check-prefix=HINTERR
--- !ELF
FileHeader:
@ -96,7 +96,7 @@ ProgramHeaders:
LastSec: .dynamic
# RUN: yaml2obj --docnum=2 %s -o %t
# RUN: not llvm-elfabi --input-format=ELF --output-format=IFS --output=%t.tbe --hint-ifs-target="x86_64-unknown-linux-gnu" %t 2>&1 | FileCheck %s -DMSG="endianness" --check-prefix=HINTERR
# RUN: not llvm-ifs --input-format=ELF --output-format=IFS --output=%t.tbe --hint-ifs-target="x86_64-unknown-linux-gnu" %t 2>&1 | FileCheck %s -DMSG="endianness" --check-prefix=HINTERR
--- !ELF
FileHeader:
@ -140,4 +140,4 @@ ProgramHeaders:
LastSec: .dynamic
# RUN: yaml2obj --docnum=3 %s -o %t
# RUN: not llvm-elfabi --input-format=ELF --output-format=IFS --output=%t.tbe --hint-ifs-target="x86_64-unknown-linux-gnu" %t 2>&1 | FileCheck %s -DMSG="bit width" --check-prefix=HINTERR
# RUN: not llvm-ifs --input-format=ELF --output-format=IFS --output=%t.tbe --hint-ifs-target="x86_64-unknown-linux-gnu" %t 2>&1 | FileCheck %s -DMSG="bit width" --check-prefix=HINTERR

View File

@ -1,5 +1,5 @@
# RUN: yaml2obj %s -o %t
# RUN: not llvm-elfabi --input-format=ELF --output-format=IFS --output=%t.tbe %t 2>&1 | FileCheck %s
# RUN: not llvm-ifs --input-format=ELF --output-format=IFS --output=%t.tbe %t 2>&1 | FileCheck %s
!ELF
FileHeader:

View File

@ -1,5 +1,5 @@
# RUN: yaml2obj %s -o %t
# RUN: not llvm-elfabi --input-format=ELF --output-format=IFS --output=%t.tbe %t 2>&1 | FileCheck %s
# RUN: not llvm-ifs --input-format=ELF --output-format=IFS --output=%t.tbe %t 2>&1 | FileCheck %s
!ELF
FileHeader:

View File

@ -1,5 +1,5 @@
# RUN: yaml2obj %s -o %t
# RUN: not llvm-elfabi --input-format=ELF --output-format=IFS --output=%t.tbe %t 2>&1 | FileCheck %s
# RUN: not llvm-ifs --input-format=ELF --output-format=IFS --output=%t.tbe %t 2>&1 | FileCheck %s
!ELF
FileHeader:

View File

@ -1,5 +1,5 @@
# RUN: yaml2obj %s -o %t
# RUN: llvm-elfabi --input-format=ELF --output-format=IFS --output=- %t | FileCheck %s
# RUN: llvm-ifs --input-format=ELF --output-format=IFS --output=- %t | FileCheck %s
!ELF
FileHeader:

View File

@ -1,5 +1,5 @@
# RUN: yaml2obj %s -o %t
# RUN: not llvm-elfabi --input-format=ELF --output-format=IFS --output=%t.tbe %t 2>&1 | FileCheck %s
# RUN: not llvm-ifs --input-format=ELF --output-format=IFS --output=%t.tbe %t 2>&1 | FileCheck %s
!ELF
FileHeader:

View File

@ -1,5 +1,5 @@
# RUN: yaml2obj %s -o %t
# RUN: not llvm-elfabi --input-format=ELF --output-format=IFS --output=%t.tbe %t 2>&1 | FileCheck %s
# RUN: not llvm-ifs --input-format=ELF --output-format=IFS --output=%t.tbe %t 2>&1 | FileCheck %s
!ELF
FileHeader:

View File

@ -1,5 +1,5 @@
# RUN: yaml2obj %s -o %t
# RUN: not llvm-elfabi --input-format=ELF --output-format=IFS --output=%t.tbe %t 2>&1 | FileCheck %s
# RUN: not llvm-ifs --input-format=ELF --output-format=IFS --output=%t.tbe %t 2>&1 | FileCheck %s
!ELF
FileHeader:

View File

@ -1,6 +1,6 @@
# RUN: yaml2obj %s -o %t
# RUN: llvm-elfabi --input-format=ELF --output-format=IFS --output=- %t | FileCheck %s --check-prefix=ORIGINAL
# RUN: llvm-elfabi --input-format=ELF --output-format=IFS --soname=libbest.so --output=- %t | FileCheck %s --check-prefix=REPLACED
# RUN: llvm-ifs --input-format=ELF --output-format=IFS --output=- %t | FileCheck %s --check-prefix=ORIGINAL
# RUN: llvm-ifs --input-format=ELF --output-format=IFS --soname=libbest.so --output=- %t | FileCheck %s --check-prefix=REPLACED
!ELF
FileHeader:

View File

@ -1,5 +1,5 @@
# RUN: yaml2obj %s -o %t
# RUN: not llvm-elfabi --input-format=ELF --output-format=IFS --output=%t.tbe %t 2>&1 | FileCheck %s
# RUN: not llvm-ifs --input-format=ELF --output-format=IFS --output=%t.tbe %t 2>&1 | FileCheck %s
!ELF
FileHeader:

View File

@ -1,5 +1,5 @@
# RUN: yaml2obj %s -o %t
# RUN: llvm-elfabi --input-format=ELF --output-format=IFS --output=- %t | FileCheck %s
# RUN: llvm-ifs --input-format=ELF --output-format=IFS --output=- %t | FileCheck %s
!ELF
FileHeader:

View File

@ -1,4 +1,4 @@
# RUN: llvm-elfabi --input-format=ELF --output-format=IFS --output=- %p/Inputs/gnu_hash.so | FileCheck %s
# RUN: llvm-ifs --input-format=ELF --output-format=IFS --output=- %p/Inputs/gnu_hash.so | FileCheck %s
# CHECK: --- !ifs-v1
# CHECK-NEXT: IfsVersion: 3.0
@ -9,14 +9,14 @@
# CHECK-NEXT: - libc.so.6
# CHECK-NEXT: - ld-linux-x86-64.so.2
# CHECK-NEXT: Symbols:
# CHECK-NEXT: - { Name: __gmon_start__, Type: NoType, Undefined: true, Weak: true }
# CHECK-NEXT: - { Name: _ITM_deregisterTMCloneTable, Type: NoType, Undefined: true, Weak: true }
# CHECK-NEXT: - { Name: _ITM_registerTMCloneTable, Type: NoType, Undefined: true, Weak: true }
# CHECK-NEXT: - { Name: __cxa_finalize, Type: Func, Undefined: true, Weak: true }
# CHECK-NEXT: - { Name: __tls_get_addr, Type: Func, Undefined: true }
# CHECK-NEXT: - { Name: _init, Type: Func }
# CHECK-NEXT: - { Name: _fini, Type: Func }
# CHECK-NEXT: - { Name: AGlobalInteger, Type: Object, Size: 4 }
# CHECK-NEXT: - { Name: AThreadLocalLongInteger, Type: TLS, Size: 8 }
# CHECK-NEXT: - { Name: _ITM_deregisterTMCloneTable, Type: NoType, Undefined: true, Weak: true }
# CHECK-NEXT: - { Name: _ITM_registerTMCloneTable, Type: NoType, Undefined: true, Weak: true }
# CHECK-NEXT: - { Name: _Z11rotateArrayPii, Type: Func }
# CHECK-NEXT: - { Name: __cxa_finalize, Type: Func, Undefined: true, Weak: true }
# CHECK-NEXT: - { Name: __gmon_start__, Type: NoType, Undefined: true, Weak: true }
# CHECK-NEXT: - { Name: __tls_get_addr, Type: Func, Undefined: true }
# CHECK-NEXT: - { Name: _fini, Type: Func }
# CHECK-NEXT: - { Name: _init, Type: Func }
# CHECK-NEXT: ...

View File

@ -1,4 +1,4 @@
# RUN: llvm-elfabi --input-format=ELF --output-format=IFS --output=- %p/Inputs/sysv_hash.so | FileCheck %s
# RUN: llvm-ifs --input-format=ELF --output-format=IFS --output=- %p/Inputs/sysv_hash.so | FileCheck %s
# CHECK: --- !ifs-v1
# CHECK-NEXT: IfsVersion: 3.0
@ -9,14 +9,14 @@
# CHECK-NEXT: - libc.so.6
# CHECK-NEXT: - ld-linux-x86-64.so.2
# CHECK-NEXT: Symbols:
# CHECK-NEXT: - { Name: __gmon_start__, Type: NoType, Undefined: true, Weak: true }
# CHECK-NEXT: - { Name: _init, Type: Func }
# CHECK-NEXT: - { Name: _fini, Type: Func }
# CHECK-NEXT: - { Name: _ITM_deregisterTMCloneTable, Type: NoType, Undefined: true, Weak: true }
# CHECK-NEXT: - { Name: _ITM_registerTMCloneTable, Type: NoType, Undefined: true, Weak: true }
# CHECK-NEXT: - { Name: __cxa_finalize, Type: Func, Undefined: true, Weak: true }
# CHECK-NEXT: - { Name: AGlobalInteger, Type: Object, Size: 4 }
# CHECK-NEXT: - { Name: AThreadLocalLongInteger, Type: TLS, Size: 8 }
# CHECK-NEXT: - { Name: _ITM_deregisterTMCloneTable, Type: NoType, Undefined: true, Weak: true }
# CHECK-NEXT: - { Name: _ITM_registerTMCloneTable, Type: NoType, Undefined: true, Weak: true }
# CHECK-NEXT: - { Name: _Z11rotateArrayPii, Type: Func }
# CHECK-NEXT: - { Name: __cxa_finalize, Type: Func, Undefined: true, Weak: true }
# CHECK-NEXT: - { Name: __gmon_start__, Type: NoType, Undefined: true, Weak: true }
# CHECK-NEXT: - { Name: __tls_get_addr, Type: Func, Undefined: true }
# CHECK-NEXT: - { Name: _fini, Type: Func }
# CHECK-NEXT: - { Name: _init, Type: Func }
# CHECK-NEXT: ...

View File

@ -1,9 +1,8 @@
# RUN: not llvm-ifs -action write-ifs -o - %s %S/object.ifs 2>&1 | \
# RUN: not llvm-ifs --input-format=IFS --output-format=IFS -o - %s %S/object.ifs 2>&1 | \
# RUN: FileCheck %s --check-prefixes=CHECK-IFS
# CHECK-IFS: error: Interface Stub: Triple Mismatch.
# CHECK-IFS: error: Interface Stub: Target Mismatch.
# CHECK-IFS-NEXT: Filenames:
# CHECK-IFS-NEXT: Triple Values: mips-unknown-linux x86_64-unknown-linux-gnu
--- !ifs-v1
IfsVersion: 3.0

View File

@ -1,7 +1,7 @@
# RUN: not llvm-ifs -action write-ifs -o - %s %S/object.ifs 2>&1 | \
# RUN: not llvm-ifs --input-format=IFS --output-format=IFS -o - %s %S/object.ifs 2>&1 | \
# RUN: FileCheck %s --check-prefixes=CHECK-IFS
# RUN: not llvm-ifs -action write-ifs -o - %s 2>&1 | \
# RUN: not llvm-ifs --input-format=IFS --output-format=IFS -o - %s 2>&1 | \
# RUN: FileCheck %s --check-prefixes=CHECK-IFS2
# CHECK-IFS: error: Interface Stub: IfsVersion Mismatch.

View File

@ -1,4 +1,4 @@
# RUN: not llvm-ifs -action write-ifs -o - %s %S/object.ifs 2>&1 | \
# RUN: not llvm-ifs --input-format=IFS --output-format=IFS -o - %s %S/object.ifs 2>&1 | \
# RUN: FileCheck %s --check-prefixes=CHECK-IFS
# Here we are testing to see if two symbols with identical names will fail to

View File

@ -1,4 +1,4 @@
# RUN: not llvm-ifs -action write-ifs -o - %s %S/func.ifs 2>&1 | \
# RUN: not llvm-ifs --input-format=IFS --output-format=IFS -o - %s %S/func.ifs 2>&1 | \
# RUN: FileCheck %s --check-prefixes=CHECK-IFS
# Here we are testing to see if two symbols with identical names will fail to

View File

@ -1,4 +1,4 @@
# RUN: llvm-ifs -action write-ifs -o - %s %S/func.ifs 2>&1 | \
# RUN: llvm-ifs --input-format=IFS --output-format=IFS -o - %s %S/func.ifs 2>&1 | \
# RUN: FileCheck %s --check-prefixes=CHECK-IFS
# CHECK-IFS: Symbols:

View File

@ -1,9 +1,8 @@
# RUN: llvm-ifs -action write-ifs -o - %s | FileCheck --check-prefixes=CHECK-DEFAULT %s
# RUN: llvm-ifs -action write-ifs -o - %s %S/weak.ifs | FileCheck --check-prefixes=CHECK-MERGE %s
# RUN: llvm-ifs --input-format=IFS --output-format=IFS -o - %s | FileCheck --check-prefixes=CHECK-DEFAULT %s
# RUN: llvm-ifs --input-format=IFS --output-format=IFS -o - %S/weak.ifs %s | FileCheck --check-prefixes=CHECK-MERGE %s
# CHECK-DEFAULT: --- !ifs-v1
# CHECK-DEFAULT-NEXT: IfsVersion: 3.0
# CHECK-DEFAULT-NEXT: Target: ''
# CHECK-DEFAULT-NEXT: Symbols: []
# CHECK-DEFAULT-NEXT: ...
@ -17,6 +16,5 @@
--- !ifs-v1
IfsVersion: 3.0
Target: ''
Symbols: []
...

View File

@ -1,4 +1,4 @@
# RUN: llvm-ifs -action write-ifs -o - %s | FileCheck %s
# RUN: llvm-ifs --input-format=IFS --output-format=IFS -o - %s | FileCheck %s
# CHECK: --- !ifs-v1
# CHECK-NEXT: IfsVersion: 3.0

View File

@ -1,4 +1,4 @@
# RUN: llvm-ifs -action write-ifs -o - %s | FileCheck %s
# RUN: llvm-ifs --input-format=IFS --output-format=IFS -o - %s | FileCheck %s
# CHECK: --- !ifs-v1
# CHECK-NEXT: IfsVersion: 3.0

View File

@ -1,5 +1,5 @@
# RUN: not llvm-elfabi --output-format=IFS --output=%t.tbe %s.NotAFileInTestingDir 2>&1 | FileCheck %s
# RUN: not llvm-ifs --output-format=IFS --output=%t.tbe %s.NotAFileInTestingDir 2>&1 | FileCheck %s
This file will not be read. An invalid file path is fed to llvm-elfabi.
This file will not be read. An invalid file path is fed to llvm-ifs.
# CHECK: error: Could not open `{{.*}}.NotAFileInTestingDir`

View File

@ -3,7 +3,7 @@
# REQUIRES: system-windows
# RUN: touch %t.TestFile
# RUN: chmod 400 %t.TestFile
# RUN: not llvm-elfabi --output-format=ELF --output=%t.TestFile %s 2>&1 | FileCheck -DMSG=%errc_EACCES %s --check-prefix=ERR
# RUN: not llvm-ifs --output-format=ELF --output=%t.TestFile %s 2>&1 | FileCheck -DMSG=%errc_EACCES %s --check-prefix=ERR
# RUN: chmod 777 %t.TestFile
# RUN: rm -rf %t.TestFile

View File

@ -5,7 +5,7 @@
# RUN: mkdir %t.TestDir
# RUN: touch %t.TestDir/Output.TestFile
# RUN: chmod 400 %t.TestDir
# RUN: not llvm-elfabi --output-format=ELF --output=%t.TestDir/Output.TestFile %s 2>&1 | FileCheck -DMSG=%errc_EACCES %s --check-prefix=ERR
# RUN: not llvm-ifs --output-format=ELF --output=%t.TestDir/Output.TestFile %s 2>&1 | FileCheck -DMSG=%errc_EACCES %s --check-prefix=ERR
# RUN: chmod 777 %t.TestDir
# RUN: rm -rf %t.TestDir

View File

@ -1,16 +1,14 @@
# RUN: llvm-ifs -action write-ifs -o - %s %S/object.ifs | \
# RUN: llvm-ifs --input-format=IFS --output-format=IFS -o - %s %S/object.ifs | \
# RUN: FileCheck %s --check-prefixes=CHECK-IFS
# RUN: llvm-ifs -action write-bin -o - %s %S/object.ifs | \
# RUN: llvm-ifs --input-format=IFS --output-format=ELF -o - %s %S/object.ifs | \
# RUN: llvm-readelf --all - | FileCheck %s --check-prefixes=CHECK-ELF
# RUN: llvm-ifs -action write-bin -o - %s %S/object.ifs -use-interfacestub | \
# RUN: llvm-readelf --all - | FileCheck %s --check-prefixes=CHECK-ELF
# RUN: llvm-ifs -action write-bin -force-format TBD -o - %s %S/object.ifs | \
# RUN: llvm-ifs --input-format=IFS --output-format=IFS --strip-ifs-target -o %t.tbd %s %S/object.ifs
# RUN: llvm-ifs --input-format=IFS --output-format=TBD --target=x86_64-apple-darwin -o - %t.tbd | \
# RUN: FileCheck %s --check-prefixes=CHECK-DARWIN-TBD3
# RUN: llvm-ifs -action write-ifs -o - %s %s | \
# RUN: llvm-ifs --input-format=IFS --output-format=IFS -o - %s %s | \
# RUN: FileCheck %s --check-prefixes=CHECK-MERGE-IFS
# CHECK-IFS: --- !ifs-v1

View File

@ -1,4 +1,4 @@
# RUN: llvm-elfabi --output-format=IFS --output=- %s | FileCheck %s
# RUN: llvm-ifs --output-format=IFS --output=- %s | FileCheck %s
--- !ifs-v1
IfsVersion: 3.0

View File

@ -1,4 +1,4 @@
# RUN: llvm-elfabi --output-format=IFS --output=- %s | FileCheck %s
# RUN: llvm-ifs --output-format=IFS --output=- %s | FileCheck %s
--- !ifs-v1
SoName: somelib.so
@ -17,9 +17,9 @@ Symbols:
# CHECK-NEXT: SoName: somelib.so
# CHECK-NEXT: Target: { ObjectFormat: ELF, Arch: x86_64, Endianness: little, BitWidth: 64 }
# CHECK-NEXT: Symbols:
# CHECK-NEXT: - { Name: foo, Type: Func }
# CHECK-NEXT: - { Name: bar, Type: Object, Size: 42 }
# CHECK-NEXT: - { Name: baz, Type: Object, Size: 8 }
# CHECK-NEXT: - { Name: not, Type: Object, Size: 128, Undefined: true }
# CHECK-NEXT: - { Name: foo, Type: Func }
# CHECK-NEXT: - { Name: nor, Type: Func, Undefined: true }
# CHECK-NEXT: - { Name: not, Type: Object, Size: 128, Undefined: true }
# CHECK-NEXT: ...

View File

@ -1,4 +1,4 @@
# RUN: llvm-ifs --action write-bin -force-format TBD -o - %s | FileCheck %s
# RUN: llvm-ifs --input-format=IFS --output-format=TBD -o - %s | FileCheck %s
# CHECK: --- !tapi-tbd-v3
# CHECK-NEXT: archs: [ arm64 ]

View File

@ -1,4 +1,4 @@
# RUN: llvm-ifs --action write-bin -force-format TBD -o - %s | FileCheck %s
# RUN: llvm-ifs --input-format=IFS --output-format=TBD -o - %s | FileCheck %s
# CHECK: --- !tapi-tbd-v3
# CHECK-NEXT: archs: [ arm64 ]

View File

@ -1,7 +1,7 @@
# RUN: llvm-ifs -action write-ifs -o - %s %S/func.ifs %S/object.ifs %S/weak.ifs | \
# RUN: llvm-ifs --input-format=IFS --output-format=IFS -o - %s %S/func.ifs %S/object.ifs %S/weak.ifs | \
# RUN: FileCheck %s --check-prefixes=CHECK-IFS
# RUN: llvm-ifs -action write-bin -o - %s %S/func.ifs %S/object.ifs %S/weak.ifs | \
# RUN: llvm-ifs --input-format=IFS --output-format=ELF -o - %s %S/func.ifs %S/object.ifs %S/weak.ifs | \
# RUN: llvm-readelf --all - | FileCheck %s --check-prefixes=CHECK-ELF
# CHECK-IFS: --- !ifs-v1

View File

@ -1,7 +1,7 @@
# RUN: llvm-ifs -action write-ifs -o - %s | \
# RUN: llvm-ifs --input-format=IFS --output-format=IFS -o - %s | \
# RUN: FileCheck %s --check-prefixes=CHECK-IFS
# RUN: llvm-ifs -action write-bin -o - %s | \
# RUN: llvm-ifs --input-format=IFS --output-format=ELF -o - %s | \
# RUN: llvm-readelf --all - | FileCheck %s --check-prefixes=CHECK-ELF
# CHECK-IFS: --- !ifs-v1

View File

@ -1,7 +1,7 @@
## Test running llvm-elfabi without specifying a valid target.
## Test running llvm-ifs without specifying a valid target.
# RUN: not llvm-elfabi --output=%t %s 2>&1 | FileCheck %s --check-prefix=MISSING
# RUN: not llvm-elfabi --output-format=nope --output=%t %s 2>&1 | FileCheck %s --check-prefix=INVALID
# RUN: not llvm-ifs --output=%t %s 2>&1 | FileCheck %s --check-prefix=MISSING
# RUN: not llvm-ifs --output-format=nope --output=%t %s 2>&1 | FileCheck %s --check-prefix=INVALID
--- !ifs-v1
SoName: somelib.so
@ -10,6 +10,6 @@ Target: { ObjectFormat: ELF, Arch: x86_64, Endianness: little, BitWidth: 64 }
Symbols: []
...
# MISSING: llvm-elfabi: for the --output-format option: must be specified at least once!
# MISSING: {{llvm-ifs(\.exe)?}}: for the --output-format option: must be specified at least once!
# INVALID: llvm-elfabi: for the --output-format option: Cannot find option named 'nope'!
# INVALID: {{llvm-ifs(\.exe)?}}: for the --output-format option: Cannot find option named 'nope'!

View File

@ -1,8 +1,8 @@
## Test writing unchanged content to TBE file with --write-if-changed flag.
# RUN: llvm-elfabi --input-format=ELF --output-format=IFS --output=%t %p/Inputs/gnu_hash.so
# RUN: llvm-ifs --input-format=ELF --output-format=IFS --output=%t %p/Inputs/gnu_hash.so
# RUN: env TZ=GMT touch -m -t 197001010000 %t
# RUN: llvm-elfabi --input-format=ELF --output-format=IFS --output=%t --write-if-changed %p/Inputs/gnu_hash.so
# RUN: llvm-ifs --input-format=ELF --output-format=IFS --output=%t --write-if-changed %p/Inputs/gnu_hash.so
# RUN: env TZ=GMT ls -l %t | FileCheck %s
# CHECK: {{[[:space:]]1970}}

View File

@ -1,8 +1,8 @@
## Test writing unchanged content to ELF Stub file with --write-if-changed flag.
# RUN: llvm-elfabi --output-format=ELF --output=%t %s
# RUN: llvm-ifs --output-format=ELF --output=%t %s
# RUN: env TZ=GMT touch -m -t 197001010000 %t
# RUN: llvm-elfabi --output-format=ELF --output=%t --write-if-changed %s
# RUN: llvm-ifs --output-format=ELF --output=%t --write-if-changed %s
# RUN: env TZ=GMT ls -l %t | FileCheck %s
--- !ifs-v1

View File

@ -3,28 +3,28 @@
## * Section headers are stripped but there is a DT_GNU_HASH dynamic tag.
## * Section headers are stripped but there is a DT_HASH dynamic tag.
## Test if llvm-elfabi reads DT_SYMTAB size through section headers by puting the wrong terminator in DT_GNU_HASH.
## Test if llvm-ifs reads DT_SYMTAB size through section headers by puting the wrong terminator in DT_GNU_HASH.
# RUN: yaml2obj %s -o %tfull -DGNUHASHVALUE="[0x9]" -DTAG1="DT_GNU_HASH" -DVAL1="0xC00"
# RUN: llvm-elfabi --input-format=ELF --output-format=IFS --output=- %tfull | FileCheck %s
# RUN: llvm-ifs --input-format=ELF --output-format=IFS --output=- %tfull | FileCheck %s
## Test if llvm-elfabi fails to read DT_SYMTAB size through section headers when the value of sh_entsize is invalid.
## Test if llvm-ifs fails to read DT_SYMTAB size through section headers when the value of sh_entsize is invalid.
# RUN: yaml2obj %s -o %tfull -DGNUHASHVALUE="[0x9]" -DTAG1="DT_GNU_HASH" -DVAL1="0xC00" -DENTSIZE="0x19"
# RUN: not llvm-elfabi --input-format=ELF --output-format=IFS --output=- %tfull 2>&1 | FileCheck %s --check-prefix=BADENTSIZE
# RUN: not llvm-ifs --input-format=ELF --output-format=IFS --output=- %tfull 2>&1 | FileCheck %s --check-prefix=BADENTSIZE
## Test if llvm-elfabi reads DT_SYMTAB size through DT_GNU_HASH.
## Test if llvm-ifs reads DT_SYMTAB size through DT_GNU_HASH.
# RUN: yaml2obj %s -o %tw.gnu.hash -DGNUHASHVALUE="[0x8, 0x9]" -DTAG1="DT_GNU_HASH" -DVAL1="0xC00" -DNOHEADER="true"
# RUN: llvm-elfabi --input-format=ELF --output-format=IFS --output=- %tw.gnu.hash | FileCheck %s
# RUN: llvm-ifs --input-format=ELF --output-format=IFS --output=- %tw.gnu.hash | FileCheck %s
## Test if llvm-elfabi fails to read DT_SYMTAB size through DT_GNU_HASH when there is no terminator.
## Test if llvm-ifs fails to read DT_SYMTAB size through DT_GNU_HASH when there is no terminator.
# RUN: yaml2obj %s -o %tw.gnu.hash -DGNUHASHVALUE="[0x8, 0xA]" -DTAG1="DT_GNU_HASH" -DVAL1="0xC00" -DNOHEADER="true"
# RUN: not llvm-elfabi --input-format=ELF --output-format=IFS --output=- %tw.gnu.hash 2>&1 | FileCheck %s --check-prefix=NOTERMINATOR
# RUN: not llvm-ifs --input-format=ELF --output-format=IFS --output=- %tw.gnu.hash 2>&1 | FileCheck %s --check-prefix=NOTERMINATOR
# CHECK: --- !ifs-v1
# CHECK-NEXT: IfsVersion: 3.0
# CHECK-NEXT: Target: { ObjectFormat: ELF, Arch: AArch64, Endianness: little, BitWidth: 64 }
# CHECK-NEXT: Symbols:
# CHECK-NEXT: - { Name: foo, Type: Func, Undefined: true }
# CHECK-NEXT: - { Name: bar, Type: Object, Size: 0, Undefined: true }
# CHECK-NEXT: - { Name: foo, Type: Func, Undefined: true }
# CHECK-NEXT: ...
# BADENTSIZE: SHT_DYNSYM section has sh_size (72) % sh_entsize (25) that is not 0

View File

@ -1,4 +1,4 @@
# RUN: not llvm-elfabi --input-format=ELF --output-format=IFS --output=%t %s 2>&1 | FileCheck %s
# RUN: not llvm-ifs --input-format=ELF --output-format=IFS --output=%t %s 2>&1 | FileCheck %s
--- !ifs-v1
SoName: somelib.so

View File

@ -1,4 +1,4 @@
# RUN: llvm-elfabi --input-format=IFS --output-format=IFS --output=- %s | FileCheck %s
# RUN: llvm-ifs --input-format=IFS --output-format=IFS --output=- %s | FileCheck %s
--- !ifs-v1
IfsVersion: 3.0

View File

@ -1,6 +1,6 @@
## Test reading TBE file with bad bit width.
# RUN: not llvm-elfabi --output-format=IFS --output=- %s 2>&1 | FileCheck %s
# RUN: not llvm-ifs --output-format=IFS --output=- %s 2>&1 | FileCheck %s
--- !ifs-v1
SoName: somelib.so

View File

@ -1,6 +1,6 @@
## Test reading TBE file with bad endianness.
# RUN: not llvm-elfabi --output-format=IFS --output=- %s 2>&1 | FileCheck %s
# RUN: not llvm-ifs --output-format=IFS --output=- %s 2>&1 | FileCheck %s
--- !ifs-v1
SoName: somelib.so

View File

@ -1,6 +1,6 @@
# RUN: not llvm-elfabi --output-format=IFS --output=- %s 2>&1| FileCheck %s
# RUN: not llvm-ifs --output-format=IFS --output=- %s 2>&1| FileCheck %s
This is just some text that cannot be read by llvm-elfabi.
This is just some text that cannot be read by llvm-ifs.
# CHECK: The file was not recognized as a valid object file
# CHECK: YAML failed reading as IFS

View File

@ -1,10 +1,10 @@
## Test writing tbe with stripped target information.
# RUN: llvm-elfabi --input-format=ELF --output-format=IFS --strip-ifs-target --output=- %p/Inputs/sysv_hash.so | FileCheck %s --check-prefix=NOTARGET
# RUN: llvm-elfabi --input-format=ELF --output-format=IFS --strip-ifs-arch --strip-ifs-endianness --strip-ifs-bitwidth --output=- %p/Inputs/sysv_hash.so | FileCheck %s --check-prefix=NOTARGET
# RUN: llvm-elfabi --input-format=ELF --output-format=IFS --strip-ifs-arch --output=- %p/Inputs/sysv_hash.so | FileCheck %s -DELFTARGET="ObjectFormat: ELF, Endianness: little, BitWidth: 64" --check-prefix=CHECK
# RUN: llvm-elfabi --input-format=ELF --output-format=IFS --strip-ifs-endianness --output=- %p/Inputs/sysv_hash.so | FileCheck %s -DELFTARGET="ObjectFormat: ELF, Arch: x86_64, BitWidth: 64" --check-prefix=CHECK
# RUN: llvm-elfabi --input-format=ELF --output-format=IFS --strip-ifs-bitwidth --output=- %p/Inputs/sysv_hash.so | FileCheck %s -DELFTARGET="ObjectFormat: ELF, Arch: x86_64, Endianness: little" --check-prefix=CHECK
# RUN: llvm-ifs --input-format=ELF --output-format=IFS --strip-ifs-target --output=- %p/Inputs/sysv_hash.so | FileCheck %s --check-prefix=NOTARGET
# RUN: llvm-ifs --input-format=ELF --output-format=IFS --strip-ifs-arch --strip-ifs-endianness --strip-ifs-bitwidth --output=- %p/Inputs/sysv_hash.so | FileCheck %s --check-prefix=NOTARGET
# RUN: llvm-ifs --input-format=ELF --output-format=IFS --strip-ifs-arch --output=- %p/Inputs/sysv_hash.so | FileCheck %s -DELFTARGET="ObjectFormat: ELF, Endianness: little, BitWidth: 64" --check-prefix=CHECK
# RUN: llvm-ifs --input-format=ELF --output-format=IFS --strip-ifs-endianness --output=- %p/Inputs/sysv_hash.so | FileCheck %s -DELFTARGET="ObjectFormat: ELF, Arch: x86_64, BitWidth: 64" --check-prefix=CHECK
# RUN: llvm-ifs --input-format=ELF --output-format=IFS --strip-ifs-bitwidth --output=- %p/Inputs/sysv_hash.so | FileCheck %s -DELFTARGET="ObjectFormat: ELF, Arch: x86_64, Endianness: little" --check-prefix=CHECK
# CHECK: --- !ifs-v1

View File

@ -1,4 +1,4 @@
# RUN: llvm-ifs -action write-ifs -o - %s %S/strong.ifs | FileCheck %s --check-prefixes=CHECK-IFS
# RUN: llvm-ifs --input-format=IFS --output-format=IFS -o - %s %S/strong.ifs | FileCheck %s --check-prefixes=CHECK-IFS
# CHECK-IFS: --- !ifs-v1
# CHECK-IFS-NEXT: IfsVersion: 3.0

View File

@ -1,4 +1,4 @@
# RUN: llvm-ifs --action write-bin -force-format TBD -o - %s | FileCheck %s
# RUN: llvm-ifs --input-format=IFS --output-format=TBD -o - %s | FileCheck %s
# CHECK: --- !tapi-tbd-v3
# CHECK-NEXT: archs: [ arm64 ]

View File

@ -1,4 +1,4 @@
# RUN: llvm-ifs -action write-ifs -o - %s %S/object.ifs
# RUN: llvm-ifs --input-format=IFS --output-format=IFS -o - %s %S/object.ifs
--- !ifs-v1
IfsVersion: 3.0

View File

@ -1,4 +1,4 @@
# RUN: llvm-ifs --action write-bin -force-format TBD -o - %s | FileCheck %s
# RUN: llvm-ifs --input-format=IFS --output-format=TBD -o - %s | FileCheck %s
# CHECK: --- !tapi-tbd-v3
# CHECK-NEXT: archs: [ arm64 ]

View File

@ -1,5 +1,5 @@
# RUN: not llvm-ifs -action write-ifs -o - %s %S/Inputs/strong-mismatch-size.ifs 2>&1 | FileCheck %s --check-prefixes=CHECK-SIZE
# RUN: not llvm-ifs -action write-ifs -o - %s %S/Inputs/strong-mismatch-type.ifs 2>&1 | FileCheck %s --check-prefixes=CHECK-TYPE
# RUN: not llvm-ifs --input-format=IFS --output-format=IFS -o - %s %S/Inputs/strong-mismatch-size.ifs 2>&1 | FileCheck %s --check-prefixes=CHECK-SIZE
# RUN: not llvm-ifs --input-format=IFS --output-format=IFS -o - %s %S/Inputs/strong-mismatch-type.ifs 2>&1 | FileCheck %s --check-prefixes=CHECK-TYPE
# CHECK-SIZE: error: Interface Stub: Size Mismatch for foobar.
# CHECK-SIZE-NEXT: Filename:

View File

@ -1,4 +1,4 @@
# RUN: llvm-ifs -action write-ifs -o - %s | FileCheck %s --check-prefixes=CHECK-IFS
# RUN: llvm-ifs --input-format=IFS --output-format=IFS -o - %s | FileCheck %s --check-prefixes=CHECK-IFS
# CHECK-IFS: --- !ifs-v1
# CHECK-IFS-NEXT: IfsVersion: 3.0

View File

@ -1,6 +1,6 @@
## Test writing stub elf when symbol table contains no non-local symbol.
# RUN: llvm-elfabi --output-format=ELF --output=%t %s
# RUN: llvm-ifs --output-format=ELF --output=%t %s
# RUN: llvm-readobj -S %t | FileCheck %s -DCLASS="64-bit (0x2)" -DDE="LittleEndian (0x1)" -DHS=64 -DPHES=56 -DSHES=64 -DDYNSYMAL=8 -DDYNSYMES=24 -DDYNAMICAL=8 -DDYNAMICES=16 -DDYNTABZ=000000000
--- !ifs-v1

View File

@ -1,35 +1,35 @@
## Test writing stub elf with minimal sections.
# RUN: llvm-elfabi --output-format=ELF --output=%t.elf32l --arch=x86_64 --bitwidth=32 --endianness=little %s
# RUN: llvm-ifs --output-format=ELF --output=%t.elf32l --arch=x86_64 --bitwidth=32 --endianness=little %s
# RUN: llvm-readobj -h -S --string-dump .dynstr --string-dump .shstrtab --dyn-symbols --dynamic-table %t.elf32l | FileCheck %s -DCLASS="32-bit (0x1)" -DDE="LittleEndian (0x1)" -DHS=52 -DPHES=32 -DSHES=40 -DDYNSYMAL=4 -DDYNSYMES=16 -DDYNAMICAL=4 -DDYNAMICES=8 -DDYNTABZ=0
# RUN: llvm-elfabi --output-format=ELF --output=%t.elf32b --arch=x86_64 --bitwidth=32 --endianness=big %s
# RUN: llvm-ifs --output-format=ELF --output=%t.elf32b --arch=x86_64 --bitwidth=32 --endianness=big %s
# RUN: llvm-readobj -h -S --string-dump .dynstr --string-dump .shstrtab --dyn-symbols --dynamic-table %t.elf32b | FileCheck %s -DCLASS="32-bit (0x1)" -DDE="BigEndian (0x2)" -DHS=52 -DPHES=32 -DSHES=40 -DDYNSYMAL=4 -DDYNSYMES=16 -DDYNAMICAL=4 -DDYNAMICES=8 -DDYNTABZ=0
# RUN: llvm-elfabi --output-format=ELF --output=%t.elf64l --arch=x86_64 --bitwidth=64 --endianness=little %s
# RUN: llvm-ifs --output-format=ELF --output=%t.elf64l --arch=x86_64 --bitwidth=64 --endianness=little %s
# RUN: llvm-readobj -h -S --string-dump .dynstr --string-dump .shstrtab --dyn-symbols --dynamic-table %t.elf64l | FileCheck %s -DCLASS="64-bit (0x2)" -DDE="LittleEndian (0x1)" -DHS=64 -DPHES=56 -DSHES=64 -DDYNSYMAL=8 -DDYNSYMES=24 -DDYNAMICAL=8 -DDYNAMICES=16 -DDYNTABZ=000000000
# RUN: llvm-elfabi --output-format=ELF --output=%t.elf64l --target=x86_64-linux-gnu %s
# RUN: llvm-ifs --output-format=ELF --output=%t.elf64l --target=x86_64-linux-gnu %s
# RUN: llvm-readobj -h -S --string-dump .dynstr --string-dump .shstrtab --dyn-symbols --dynamic-table %t.elf64l | FileCheck %s -DCLASS="64-bit (0x2)" -DDE="LittleEndian (0x1)" -DHS=64 -DPHES=56 -DSHES=64 -DDYNSYMAL=8 -DDYNSYMES=24 -DDYNAMICAL=8 -DDYNAMICES=16 -DDYNTABZ=000000000
# RUN: llvm-elfabi --output-format=ELF --output=%t.elf64b --arch=x86_64 --bitwidth=64 --endianness=big %s
# RUN: llvm-ifs --output-format=ELF --output=%t.elf64b --arch=x86_64 --bitwidth=64 --endianness=big %s
# RUN: llvm-readobj -h -S --string-dump .dynstr --string-dump .shstrtab --dyn-symbols --dynamic-table %t.elf64b | FileCheck %s -DCLASS="64-bit (0x2)" -DDE="BigEndian (0x2)" -DHS=64 -DPHES=56 -DSHES=64 -DDYNSYMAL=8 -DDYNSYMES=24 -DDYNAMICAL=8 -DDYNAMICES=16 -DDYNTABZ=000000000
# RUN: not llvm-elfabi --output-format=ELF --output=%t --arch=x86_64 --bitwidth=64 --endianness=big --target=x86_64-linux-gnu %s 2>&1 | FileCheck %s --check-prefix=TRIPLEERR
# RUN: not llvm-ifs --output-format=ELF --output=%t --arch=x86_64 --bitwidth=64 --endianness=big --target=x86_64-linux-gnu %s 2>&1 | FileCheck %s --check-prefix=TRIPLEERR
# RUN: not llvm-elfabi --output-format=ELF --output=%t --bitwidth=64 --endianness=big %s 2>&1 | FileCheck %s -DMSG="Arch" --check-prefix=TARGETERR
# RUN: not llvm-ifs --output-format=ELF --output=%t --bitwidth=64 --endianness=big %s 2>&1 | FileCheck %s -DMSG="Arch" --check-prefix=TARGETERR
# RUN: not llvm-elfabi --output-format=ELF --output=%t --arch=x86_64 --endianness=big %s 2>&1 | FileCheck %s -DMSG="BitWidth" --check-prefix=TARGETERR
# RUN: not llvm-ifs --output-format=ELF --output=%t --arch=x86_64 --endianness=big %s 2>&1 | FileCheck %s -DMSG="BitWidth" --check-prefix=TARGETERR
# RUN: not llvm-elfabi --output-format=ELF --output=%t --arch=x86_64 --bitwidth=64 %s 2>&1 | FileCheck %s -DMSG="Endianness" --check-prefix=TARGETERR
# RUN: not llvm-ifs --output-format=ELF --output=%t --arch=x86_64 --bitwidth=64 %s 2>&1 | FileCheck %s -DMSG="Endianness" --check-prefix=TARGETERR
# RUN: llvm-elfabi --output-format=IFS --output=%t.target --target=x86_64-linux-gnu %s
# RUN: not llvm-elfabi --output-format=ELF --output=%t --target=aarch64-linux-gnu %t.target 2>&1 | FileCheck %s -DMSG="Triple" --check-prefix=CONFLICTERR
# RUN: llvm-ifs --output-format=IFS --output=%t.target --target=x86_64-linux-gnu %s
# RUN: not llvm-ifs --output-format=ELF --output=%t --target=aarch64-linux-gnu %t.target 2>&1 | FileCheck %s -DMSG="Triple" --check-prefix=CONFLICTERR
# RUN: llvm-elfabi --output-format=IFS --output=%t.target --arch=x86_64 --endianness=little --bitwidth=64 %s
# RUN: not llvm-elfabi --output-format=ELF --output=%t --arch=AArch64 %t.target 2>&1 | FileCheck %s -DMSG=Arch --check-prefix=CONFLICTERR
# RUN: not llvm-elfabi --output-format=ELF --output=%t --endianness=big %t.target 2>&1 | FileCheck %s -DMSG=Endianness --check-prefix=CONFLICTERR
# RUN: not llvm-elfabi --output-format=ELF --output=%t --bitwidth=32 %t.target 2>&1 | FileCheck %s -DMSG=BitWidth --check-prefix=CONFLICTERR
# RUN: llvm-ifs --output-format=IFS --output=%t.target --arch=x86_64 --endianness=little --bitwidth=64 %s
# RUN: not llvm-ifs --output-format=ELF --output=%t --arch=AArch64 %t.target 2>&1 | FileCheck %s -DMSG=Arch --check-prefix=CONFLICTERR
# RUN: not llvm-ifs --output-format=ELF --output=%t --endianness=big %t.target 2>&1 | FileCheck %s -DMSG=Endianness --check-prefix=CONFLICTERR
# RUN: not llvm-ifs --output-format=ELF --output=%t --bitwidth=32 %t.target 2>&1 | FileCheck %s -DMSG=BitWidth --check-prefix=CONFLICTERR
--- !ifs-v1
IfsVersion: 3.0

View File

@ -1,12 +0,0 @@
set(LLVM_LINK_COMPONENTS
BinaryFormat
InterfaceStub
Object
Support
TextAPI
)
add_llvm_tool(llvm-elfabi
ErrorCollector.cpp
llvm-elfabi.cpp
)

View File

@ -1,233 +0,0 @@
//===- llvm-elfabi.cpp ----------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===-----------------------------------------------------------------------===/
#include "ErrorCollector.h"
#include "llvm/InterfaceStub/ELFObjHandler.h"
#include "llvm/InterfaceStub/IFSHandler.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Errc.h"
#include "llvm/Support/FileOutputBuffer.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/WithColor.h"
#include "llvm/Support/raw_ostream.h"
#include <string>
namespace llvm {
namespace elfabi {
enum class FileFormat { IFS, ELF };
} // namespace elfabi
} // end namespace llvm
using namespace llvm;
using namespace llvm::elfabi;
// Command line flags:
cl::opt<std::string> InputFilePath(cl::Positional, cl::desc("input"),
cl::Required);
cl::opt<FileFormat> InputFormat(
"input-format", cl::desc("Specify the input file format"),
cl::values(clEnumValN(FileFormat::IFS, "IFS", "Text based ELF stub file"),
clEnumValN(FileFormat::ELF, "ELF", "ELF object file")));
cl::opt<FileFormat> OutputFormat(
"output-format", cl::desc("Specify the output file format"),
cl::values(clEnumValN(FileFormat::IFS, "IFS", "Text based ELF stub file"),
clEnumValN(FileFormat::ELF, "ELF", "ELF stub file")),
cl::Required);
cl::opt<std::string> OptArch("arch",
cl::desc("Specify the architecture, e.g. x86_64"));
cl::opt<IFSBitWidthType> OptBitWidth(
"bitwidth", cl::desc("Specify the bit width"),
cl::values(clEnumValN(IFSBitWidthType::IFS32, "32", "32 bits"),
clEnumValN(IFSBitWidthType::IFS64, "64", "64 bits")));
cl::opt<IFSEndiannessType> OptEndianness(
"endianness", cl::desc("Specify the endianness"),
cl::values(clEnumValN(IFSEndiannessType::Little, "little", "Little Endian"),
clEnumValN(IFSEndiannessType::Big, "big", "Big Endian")));
cl::opt<std::string> OptTargetTriple(
"target", cl::desc("Specify the target triple, e.g. x86_64-linux-gnu"));
cl::opt<std::string> OptTargetTripleHint(
"hint-ifs-target",
cl::desc("When --output-format is 'IFS', this flag will hint the expected "
"target triple for IFS output"));
cl::opt<bool> StripIFSArch(
"strip-ifs-arch",
cl::desc("Strip target architecture information away from IFS output"));
cl::opt<bool> StripIFSBitWidth(
"strip-ifs-bitwidth",
cl::desc("Strip target bit width information away from IFS output"));
cl::opt<bool> StripIFSEndiannessWidth(
"strip-ifs-endianness",
cl::desc("Strip target endianness information away from IFS output"));
cl::opt<bool> StripIFSTarget(
"strip-ifs-target",
cl::desc("Strip all target information away from IFS output"));
cl::opt<std::string>
SOName("soname",
cl::desc("Manually set the DT_SONAME entry of any emitted files"),
cl::value_desc("name"));
cl::opt<std::string> OutputFilePath("output", cl::desc("Output file"));
cl::opt<bool> WriteIfChanged(
"write-if-changed",
cl::desc("Write the output file only if it is new or has changed."));
/// writeIFS() writes a Text-Based ELF stub to a file using the latest version
/// of the YAML parser.
static Error writeIFS(StringRef FilePath, IFSStub &Stub) {
// Write IFS to memory first.
std::string IFSStr;
raw_string_ostream OutStr(IFSStr);
Error YAMLErr = writeIFSToOutputStream(OutStr, Stub);
if (YAMLErr)
return YAMLErr;
OutStr.flush();
if (WriteIfChanged) {
if (ErrorOr<std::unique_ptr<MemoryBuffer>> BufOrError =
MemoryBuffer::getFile(FilePath)) {
// Compare IFS output with existing IFS file.
// If IFS file unchanged, abort updating.
if ((*BufOrError)->getBuffer() == IFSStr)
return Error::success();
}
}
// Open IFS file for writing.
std::error_code SysErr;
raw_fd_ostream Out(FilePath, SysErr);
if (SysErr)
return createStringError(SysErr, "Couldn't open `%s` for writing",
FilePath.data());
Out << IFSStr;
return Error::success();
}
/// readInputFile populates an IFSStub by attempting to read the
/// input file using both the IFS and binary ELF parsers.
static Expected<std::unique_ptr<IFSStub>> readInputFile(StringRef FilePath) {
// Read in file.
ErrorOr<std::unique_ptr<MemoryBuffer>> BufOrError =
MemoryBuffer::getFile(FilePath);
if (!BufOrError) {
return createStringError(BufOrError.getError(), "Could not open `%s`",
FilePath.data());
}
std::unique_ptr<MemoryBuffer> FileReadBuffer = std::move(*BufOrError);
ErrorCollector EC(/*UseFatalErrors=*/false);
// First try to read as a binary (fails fast if not binary).
if (InputFormat.getNumOccurrences() == 0 || InputFormat == FileFormat::ELF) {
Expected<std::unique_ptr<IFSStub>> StubFromELF =
readELFFile(FileReadBuffer->getMemBufferRef());
if (StubFromELF) {
return std::move(*StubFromELF);
}
EC.addError(StubFromELF.takeError(), "BinaryRead");
}
// Fall back to reading as a ifs.
if (InputFormat.getNumOccurrences() == 0 || InputFormat == FileFormat::IFS) {
Expected<std::unique_ptr<IFSStub>> StubFromIFS =
readIFSFromBuffer(FileReadBuffer->getBuffer());
if (StubFromIFS) {
return std::move(*StubFromIFS);
}
EC.addError(StubFromIFS.takeError(), "YamlParse");
}
// If both readers fail, build a new error that includes all information.
EC.addError(createStringError(errc::not_supported,
"No file readers succeeded reading `%s` "
"(unsupported/malformed file?)",
FilePath.data()),
"ReadInputFile");
EC.escalateToFatal();
return EC.makeError();
}
static void fatalError(Error Err) {
WithColor::defaultErrorHandler(std::move(Err));
exit(1);
}
int main(int argc, char *argv[]) {
// Parse arguments.
cl::ParseCommandLineOptions(argc, argv);
Expected<std::unique_ptr<IFSStub>> StubOrErr = readInputFile(InputFilePath);
if (!StubOrErr)
fatalError(StubOrErr.takeError());
std::unique_ptr<IFSStub> TargetStub = std::move(StubOrErr.get());
// Change SoName before emitting stubs.
if (SOName.getNumOccurrences() == 1)
TargetStub->SoName = SOName;
Optional<IFSArch> OverrideArch;
Optional<IFSEndiannessType> OverrideEndianness;
Optional<IFSBitWidthType> OverrideBitWidth;
Optional<std::string> OverrideTriple;
if (OptArch.getNumOccurrences() == 1) {
OverrideArch = ELF::convertArchNameToEMachine(OptArch.getValue());
}
if (OptEndianness.getNumOccurrences() == 1)
OverrideEndianness = OptEndianness.getValue();
if (OptBitWidth.getNumOccurrences() == 1)
OverrideBitWidth = OptBitWidth.getValue();
if (OptTargetTriple.getNumOccurrences() == 1)
OverrideTriple = OptTargetTriple.getValue();
Error OverrideError =
overrideIFSTarget(*TargetStub, OverrideArch, OverrideEndianness,
OverrideBitWidth, OverrideTriple);
if (OverrideError)
fatalError(std::move(OverrideError));
switch (OutputFormat.getValue()) {
case FileFormat::IFS: {
TargetStub->IfsVersion = IFSVersionCurrent;
if (InputFormat.getValue() == FileFormat::ELF &&
OptTargetTripleHint.getNumOccurrences() == 1) {
std::error_code HintEC(1, std::generic_category());
IFSTarget HintTarget = parseTriple(OptTargetTripleHint);
if (TargetStub->Target.Arch.getValue() != HintTarget.Arch.getValue()) {
fatalError(make_error<StringError>(
"Triple hint does not match the actual architecture", HintEC));
}
if (TargetStub->Target.Endianness.getValue() !=
HintTarget.Endianness.getValue()) {
fatalError(make_error<StringError>(
"Triple hint does not match the actual endianness", HintEC));
}
if (TargetStub->Target.BitWidth.getValue() !=
HintTarget.BitWidth.getValue()) {
fatalError(make_error<StringError>(
"Triple hint does not match the actual bit width", HintEC));
}
stripIFSTarget(*TargetStub, true, false, false, false);
TargetStub->Target.Triple = OptTargetTripleHint.getValue();
} else {
stripIFSTarget(*TargetStub, StripIFSTarget, StripIFSArch,
StripIFSEndiannessWidth, StripIFSBitWidth);
}
Error IFSWriteError = writeIFS(OutputFilePath.getValue(), *TargetStub);
if (IFSWriteError)
fatalError(std::move(IFSWriteError));
break;
}
case FileFormat::ELF: {
Error TargetError = validateIFSTarget(*TargetStub, true);
if (TargetError)
fatalError(std::move(TargetError));
Error BinaryWriteError =
writeBinaryStub(OutputFilePath, *TargetStub, WriteIfChanged);
if (BinaryWriteError)
fatalError(std::move(BinaryWriteError));
break;
}
}
}

View File

@ -7,5 +7,6 @@ set(LLVM_LINK_COMPONENTS
)
add_llvm_tool(llvm-ifs
ErrorCollector.cpp
llvm-ifs.cpp
)

View File

@ -14,7 +14,7 @@
#include <vector>
using namespace llvm;
using namespace llvm::elfabi;
using namespace llvm::ifs;
void ErrorCollector::escalateToFatal() { ErrorsAreFatal = true; }

View File

@ -18,14 +18,14 @@
///
//===-----------------------------------------------------------------------===/
#ifndef LLVM_TOOLS_ELFABI_ERRORCOLLECTOR_H
#define LLVM_TOOLS_ELFABI_ERRORCOLLECTOR_H
#ifndef LLVM_TOOLS_LLVM_IFS_ERRORCOLLECTOR_H
#define LLVM_TOOLS_LLVM_IFS_ERRORCOLLECTOR_H
#include "llvm/Support/Error.h"
#include <vector>
namespace llvm {
namespace elfabi {
namespace ifs {
class ErrorCollector {
public:
@ -68,7 +68,7 @@ private:
std::vector<std::string> Tags;
};
} // end namespace elfabi
} // end namespace ifs
} // end namespace llvm
#endif // LLVM_TOOLS_ELFABI_ERRORCOLLECTOR_H
#endif // LLVM_TOOLS_LLVM_IFS_ERRORCOLLECTOR_H

View File

@ -6,6 +6,7 @@
//
//===-----------------------------------------------------------------------===/
#include "ErrorCollector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/ADT/Triple.h"
@ -34,41 +35,68 @@
using namespace llvm;
using namespace llvm::yaml;
using namespace llvm::MachO;
using namespace llvm::ifs;
#define DEBUG_TYPE "llvm-ifs"
namespace {
const VersionTuple IFSVersionCurrent(3, 0);
const VersionTuple IfsVersionCurrent(3, 0);
enum class FileFormat { IFS, ELF, TBD };
} // end anonymous namespace
static cl::opt<std::string> Action("action", cl::desc("<llvm-ifs action>"),
cl::value_desc("write-ifs | write-bin"),
cl::init("write-ifs"));
static cl::opt<std::string> ForceFormat("force-format",
cl::desc("<force object format>"),
cl::value_desc("ELF | TBD"),
cl::init(""));
static cl::list<std::string> InputFilenames(cl::Positional,
cl::desc("<input ifs files>"),
cl::ZeroOrMore);
static cl::opt<std::string> OutputFilename("o", cl::desc("<output file>"),
cl::value_desc("path"));
static cl::opt<bool> UseInterfaceStub(
"use-interfacestub",
cl::desc("Write output ELF file using latest InterfaceStub backend"),
cl::init(false));
enum class IFSSymbolType {
NoType = 0,
Object,
Func,
// Type information is 4 bits, so 16 is safely out of range.
Unknown = 16,
};
// TODO: Use OptTable for option parsing in the future.
// Command line flags:
cl::list<std::string> InputFilePaths(cl::Positional, cl::desc("input"),
cl::ZeroOrMore);
cl::opt<FileFormat> InputFormat(
"input-format", cl::desc("Specify the input file format"),
cl::values(clEnumValN(FileFormat::IFS, "IFS", "Text based ELF stub file"),
clEnumValN(FileFormat::ELF, "ELF", "ELF object file")));
cl::opt<FileFormat> OutputFormat(
"output-format", cl::desc("Specify the output file format"),
cl::values(clEnumValN(FileFormat::IFS, "IFS", "Text based ELF stub file"),
clEnumValN(FileFormat::ELF, "ELF", "ELF stub file"),
clEnumValN(FileFormat::TBD, "TBD", "Apple TBD text stub file")),
cl::Required);
cl::opt<std::string> OptArch("arch",
cl::desc("Specify the architecture, e.g. x86_64"));
cl::opt<IFSBitWidthType> OptBitWidth(
"bitwidth", cl::desc("Specify the bit width"),
cl::values(clEnumValN(IFSBitWidthType::IFS32, "32", "32 bits"),
clEnumValN(IFSBitWidthType::IFS64, "64", "64 bits")));
cl::opt<IFSEndiannessType> OptEndianness(
"endianness", cl::desc("Specify the endianness"),
cl::values(clEnumValN(IFSEndiannessType::Little, "little", "Little Endian"),
clEnumValN(IFSEndiannessType::Big, "big", "Big Endian")));
cl::opt<std::string> OptTargetTriple(
"target", cl::desc("Specify the target triple, e.g. x86_64-linux-gnu"));
cl::opt<std::string> OptTargetTripleHint(
"hint-ifs-target",
cl::desc("When --output-format is 'IFS', this flag will hint the expected "
"target triple for IFS output"));
cl::opt<bool> StripIFSArch(
"strip-ifs-arch",
cl::desc("Strip target architecture information away from IFS output"));
cl::opt<bool> StripIFSBitWidth(
"strip-ifs-bitwidth",
cl::desc("Strip target bit width information away from IFS output"));
cl::opt<bool> StripIFSEndiannessWidth(
"strip-ifs-endianness",
cl::desc("Strip target endianness information away from IFS output"));
cl::opt<bool> StripIFSTarget(
"strip-ifs-target",
cl::desc("Strip all target information away from IFS output"));
cl::opt<std::string>
SoName("soname",
cl::desc("Manually set the DT_SONAME entry of any emitted files"),
cl::value_desc("name"));
cl::opt<std::string> OutputFilePath("output", cl::desc("Output file"));
cl::alias OutputFilePathA("o", cl::desc("Alias for --output"),
cl::aliasopt(OutputFilePath));
cl::opt<bool> WriteIfChanged(
"write-if-changed",
cl::desc("Write the output file only if it is new or has changed."));
static std::string getTypeName(IFSSymbolType Type) {
switch (Type) {
@ -78,108 +106,14 @@ static std::string getTypeName(IFSSymbolType Type) {
return "Func";
case IFSSymbolType::Object:
return "Object";
case IFSSymbolType::TLS:
return "TLS";
case IFSSymbolType::Unknown:
return "Unknown";
}
llvm_unreachable("Unexpected ifs symbol type.");
}
struct IFSSymbol {
IFSSymbol() = default;
IFSSymbol(std::string SymbolName) : Name(SymbolName) {}
std::string Name;
uint64_t Size;
IFSSymbolType Type;
bool Weak;
Optional<std::string> Warning;
bool operator<(const IFSSymbol &RHS) const { return Name < RHS.Name; }
};
LLVM_YAML_IS_SEQUENCE_VECTOR(IFSSymbol)
namespace llvm {
namespace yaml {
/// YAML traits for IFSSymbolType.
template <> struct ScalarEnumerationTraits<IFSSymbolType> {
static void enumeration(IO &IO, IFSSymbolType &SymbolType) {
IO.enumCase(SymbolType, "NoType", IFSSymbolType::NoType);
IO.enumCase(SymbolType, "Func", IFSSymbolType::Func);
IO.enumCase(SymbolType, "Object", IFSSymbolType::Object);
IO.enumCase(SymbolType, "Unknown", IFSSymbolType::Unknown);
// Treat other symbol types as noise, and map to Unknown.
if (!IO.outputting() && IO.matchEnumFallback())
SymbolType = IFSSymbolType::Unknown;
}
};
/// YAML traits for IFSSymbol.
template <> struct MappingTraits<IFSSymbol> {
static void mapping(IO &IO, IFSSymbol &Symbol) {
IO.mapRequired("Name", Symbol.Name);
IO.mapRequired("Type", Symbol.Type);
// The need for symbol size depends on the symbol type.
if (Symbol.Type == IFSSymbolType::NoType)
IO.mapOptional("Size", Symbol.Size, (uint64_t)0);
else if (Symbol.Type == IFSSymbolType::Func)
Symbol.Size = 0;
else
IO.mapRequired("Size", Symbol.Size);
IO.mapOptional("Weak", Symbol.Weak, false);
IO.mapOptional("Warning", Symbol.Warning);
}
// Compacts symbol information into a single line.
static const bool flow = true;
};
} // namespace yaml
} // namespace llvm
// A cumulative representation of ELF stubs.
// Both textual and binary stubs will read into and write from this object.
class IFSStub {
// TODO: Add support for symbol versioning.
public:
VersionTuple IfsVersion;
std::string Triple;
std::string ObjectFileFormat;
Optional<std::string> SOName;
std::vector<std::string> NeededLibs;
std::vector<IFSSymbol> Symbols;
IFSStub() = default;
IFSStub(const IFSStub &Stub)
: IfsVersion(Stub.IfsVersion), Triple(Stub.Triple),
ObjectFileFormat(Stub.ObjectFileFormat), SOName(Stub.SOName),
NeededLibs(Stub.NeededLibs), Symbols(Stub.Symbols) {}
IFSStub(IFSStub &&Stub)
: IfsVersion(std::move(Stub.IfsVersion)), Triple(std::move(Stub.Triple)),
ObjectFileFormat(std::move(Stub.ObjectFileFormat)),
SOName(std::move(Stub.SOName)), NeededLibs(std::move(Stub.NeededLibs)),
Symbols(std::move(Stub.Symbols)) {}
};
namespace llvm {
namespace yaml {
/// YAML traits for IFSStub objects.
template <> struct MappingTraits<IFSStub> {
static void mapping(IO &IO, IFSStub &Stub) {
if (!IO.mapTag("!ifs-v1", true))
IO.setError("Not a .ifs YAML file.");
auto OldContext = IO.getContext();
IO.setContext(&Stub);
IO.mapRequired("IfsVersion", Stub.IfsVersion);
IO.mapOptional("Target", Stub.Triple);
IO.mapOptional("SOName", Stub.SOName);
IO.mapOptional("NeededLibs", Stub.NeededLibs);
IO.mapRequired("Symbols", Stub.Symbols);
IO.setContext(&OldContext);
}
};
} // namespace yaml
} // namespace llvm
static Expected<std::unique_ptr<IFSStub>> readInputFile(StringRef FilePath) {
// Read in file.
ErrorOr<std::unique_ptr<MemoryBuffer>> BufOrError =
@ -189,19 +123,46 @@ static Expected<std::unique_ptr<IFSStub>> readInputFile(StringRef FilePath) {
FilePath.data());
std::unique_ptr<MemoryBuffer> FileReadBuffer = std::move(*BufOrError);
yaml::Input YamlIn(FileReadBuffer->getBuffer());
std::unique_ptr<IFSStub> Stub(new IFSStub());
YamlIn >> *Stub;
ErrorCollector EC(/*UseFatalErrors=*/false);
if (std::error_code Err = YamlIn.error())
return createStringError(Err, "Failed reading Interface Stub File.");
// First try to read as a binary (fails fast if not binary).
if (InputFormat.getNumOccurrences() == 0 || InputFormat == FileFormat::ELF) {
Expected<std::unique_ptr<IFSStub>> StubFromELF =
readELFFile(FileReadBuffer->getMemBufferRef());
if (StubFromELF) {
(*StubFromELF)->IfsVersion = IfsVersionCurrent;
return std::move(*StubFromELF);
}
EC.addError(StubFromELF.takeError(), "BinaryRead");
}
if (Stub->IfsVersion > IFSVersionCurrent)
return make_error<StringError>(
"IFS version " + Stub->IfsVersion.getAsString() + " is unsupported.",
std::make_error_code(std::errc::invalid_argument));
// Fall back to reading as a ifs.
if (InputFormat.getNumOccurrences() == 0 || InputFormat == FileFormat::IFS) {
Expected<std::unique_ptr<IFSStub>> StubFromIFS =
readIFSFromBuffer(FileReadBuffer->getBuffer());
if (StubFromIFS) {
if ((*StubFromIFS)->IfsVersion > IfsVersionCurrent)
EC.addError(
createStringError(errc::not_supported,
"IFS version " +
(*StubFromIFS)->IfsVersion.getAsString() +
" is unsupported."),
"ReadInputFile");
else
return std::move(*StubFromIFS);
} else {
EC.addError(StubFromIFS.takeError(), "YamlParse");
}
}
return std::move(Stub);
// If both readers fail, build a new error that includes all information.
EC.addError(createStringError(errc::not_supported,
"No file readers succeeded reading `%s` "
"(unsupported/malformed file?)",
FilePath.data()),
"ReadInputFile");
EC.escalateToFatal();
return EC.makeError();
}
static int writeTbdStub(const Triple &T, const std::vector<IFSSymbol> &Symbols,
@ -220,10 +181,6 @@ static int writeTbdStub(const Triple &T, const std::vector<IFSSymbol> &Symbols,
if (T.isiOS())
return llvm::MachO::PlatformKind::iOS;
// TODO: Add an option for ForceTriple, but keep ForceFormat for now.
if (ForceFormat == "TBD")
return llvm::MachO::PlatformKind::macOS;
return createStringError(errc::not_supported, "Invalid Platform.\n");
}(T);
@ -266,209 +223,69 @@ static int writeTbdStub(const Triple &T, const std::vector<IFSSymbol> &Symbols,
return 0;
}
static int writeElfStub(const Triple &T, const std::vector<IFSSymbol> &Symbols,
const StringRef Format, raw_ostream &Out) {
SmallString<0> Storage;
Storage.clear();
raw_svector_ostream OS(Storage);
OS << "--- !ELF\n";
OS << "FileHeader:\n";
OS << " Class: ELFCLASS";
OS << (T.isArch64Bit() ? "64" : "32");
OS << "\n";
OS << " Data: ELFDATA2";
OS << (T.isLittleEndian() ? "LSB" : "MSB");
OS << "\n";
OS << " Type: ET_DYN\n";
OS << " Machine: "
<< llvm::StringSwitch<llvm::StringRef>(T.getArchName())
.Case("x86_64", "EM_X86_64")
.Case("i386", "EM_386")
.Case("i686", "EM_386")
.Case("aarch64", "EM_AARCH64")
.Case("amdgcn", "EM_AMDGPU")
.Case("r600", "EM_AMDGPU")
.Case("arm", "EM_ARM")
.Case("thumb", "EM_ARM")
.Case("avr", "EM_AVR")
.Case("mips", "EM_MIPS")
.Case("mipsel", "EM_MIPS")
.Case("mips64", "EM_MIPS")
.Case("mips64el", "EM_MIPS")
.Case("msp430", "EM_MSP430")
.Case("ppc", "EM_PPC")
.Case("ppc64", "EM_PPC64")
.Case("ppc64le", "EM_PPC64")
.Case("x86", T.isOSIAMCU() ? "EM_IAMCU" : "EM_386")
.Case("x86_64", "EM_X86_64")
.Default("EM_NONE")
<< "\nSections:"
<< "\n - Name: .text"
<< "\n Type: SHT_PROGBITS"
<< "\n - Name: .data"
<< "\n Type: SHT_PROGBITS"
<< "\n - Name: .rodata"
<< "\n Type: SHT_PROGBITS"
<< "\nSymbols:\n";
for (const auto &Symbol : Symbols) {
OS << " - Name: " << Symbol.Name << "\n"
<< " Type: STT_";
switch (Symbol.Type) {
default:
case IFSSymbolType::NoType:
OS << "NOTYPE";
break;
case IFSSymbolType::Object:
OS << "OBJECT";
break;
case IFSSymbolType::Func:
OS << "FUNC";
break;
}
OS << "\n Section: .text"
<< "\n Binding: STB_" << (Symbol.Weak ? "WEAK" : "GLOBAL")
<< "\n";
}
OS << "...\n";
std::string YamlStr = std::string(OS.str());
// Only or debugging. Not an offical format.
LLVM_DEBUG({
if (ForceFormat == "ELFOBJYAML") {
Out << YamlStr;
return 0;
}
});
yaml::Input YIn(YamlStr);
auto ErrHandler = [](const Twine &Msg) {
WithColor::error(errs(), "llvm-ifs") << Msg << "\n";
};
return convertYAML(YIn, Out, ErrHandler) ? 0 : 1;
static void fatalError(Error Err) {
WithColor::defaultErrorHandler(std::move(Err));
exit(1);
}
static Error convertIFSStub(const IFSStub &IfsStub, elfabi::IFSStub &ElfStub) {
ElfStub.IfsVersion = IfsStub.IfsVersion;
ElfStub.SoName = IfsStub.SOName;
ElfStub.Target.Triple = IfsStub.Triple;
ElfStub.NeededLibs = IfsStub.NeededLibs;
for (const IFSSymbol &IfsSymbol : IfsStub.Symbols) {
elfabi::IFSSymbol ElfSymbol(IfsSymbol.Name);
switch (IfsSymbol.Type) {
case IFSSymbolType::Func:
ElfSymbol.Type = elfabi::IFSSymbolType::Func;
break;
case IFSSymbolType::NoType:
ElfSymbol.Type = elfabi::IFSSymbolType::NoType;
break;
case IFSSymbolType::Object:
ElfSymbol.Type = elfabi::IFSSymbolType::Object;
break;
default:
ElfSymbol.Type = elfabi::IFSSymbolType::Unknown;
break;
// TODO: Add support for TLS?
/// writeIFS() writes a Text-Based ELF stub to a file using the latest version
/// of the YAML parser.
static Error writeIFS(StringRef FilePath, IFSStub &Stub) {
// Write IFS to memory first.
std::string IFSStr;
raw_string_ostream OutStr(IFSStr);
Error YAMLErr = writeIFSToOutputStream(OutStr, Stub);
if (YAMLErr)
return YAMLErr;
OutStr.flush();
if (WriteIfChanged) {
if (ErrorOr<std::unique_ptr<MemoryBuffer>> BufOrError =
MemoryBuffer::getFile(FilePath)) {
// Compare IFS output with the existing IFS file. If unchanged, avoid changing the file.
if ((*BufOrError)->getBuffer() == IFSStr)
return Error::success();
}
ElfSymbol.Size = IfsSymbol.Size;
ElfSymbol.Undefined = false;
ElfSymbol.Weak = IfsSymbol.Weak;
ElfSymbol.Warning = IfsSymbol.Warning;
ElfStub.Symbols.push_back(ElfSymbol);
}
return llvm::elfabi::validateIFSTarget(ElfStub, true);
}
static int writeIfso(const IFSStub &Stub, bool IsWriteIfs) {
std::string ObjectFileFormat =
ForceFormat.empty() ? std::string("ELF") : ForceFormat;
// Use InterfaceStub library if the option is enabled and output
// format is ELF.
if (UseInterfaceStub && (!IsWriteIfs) && ObjectFileFormat != "TBD") {
elfabi::IFSStub IfsStub;
Error ConvertError = convertIFSStub(Stub, IfsStub);
if (ConvertError) {
return -1;
}
Error BinaryWriteError = elfabi::writeBinaryStub(OutputFilename, IfsStub);
if (BinaryWriteError) {
return -1;
}
return 0;
}
// Open file for writing.
// Open IFS file for writing.
std::error_code SysErr;
raw_fd_ostream Out(OutputFilename, SysErr);
if (SysErr) {
WithColor::error() << "Couldn't open " << OutputFilename
<< " for writing.\n";
return -1;
}
if (IsWriteIfs) {
yaml::Output YamlOut(Out, NULL, /*WrapColumn =*/0);
YamlOut << const_cast<IFSStub &>(Stub);
return 0;
}
if (ObjectFileFormat == "ELF" || ForceFormat == "ELFOBJYAML")
return writeElfStub(llvm::Triple(Stub.Triple), Stub.Symbols,
Stub.ObjectFileFormat, Out);
if (ObjectFileFormat == "TBD")
return writeTbdStub(llvm::Triple(Stub.Triple), Stub.Symbols,
Stub.ObjectFileFormat, Out);
WithColor::error()
<< "Invalid ObjectFileFormat: Only ELF and TBD are supported.\n";
return -1;
raw_fd_ostream Out(FilePath, SysErr);
if (SysErr)
return createStringError(SysErr, "Couldn't open `%s` for writing",
FilePath.data());
Out << IFSStr;
return Error::success();
}
// TODO: Drop ObjectFileFormat, it can be subsumed from the triple.
// New Interface Stubs Yaml Format:
// --- !experimental-ifs-v2
// IfsVersion: 2.0
// Triple: <llvm triple>
// ObjectFileFormat: <ELF | others not yet supported>
// Symbols:
// _ZSymbolName: { Type: <type> }
// ...
int main(int argc, char *argv[]) {
// Parse arguments.
cl::ParseCommandLineOptions(argc, argv);
if (InputFilenames.empty())
InputFilenames.push_back("-");
if (InputFilePaths.empty())
InputFilePaths.push_back("-");
// If input files are more than one, they can only be IFS files.
if (InputFilePaths.size() > 1)
InputFormat.setValue(FileFormat::IFS);
// Attempt to merge input.
IFSStub Stub;
std::map<std::string, IFSSymbol> SymbolMap;
std::string PreviousInputFilePath;
for (const std::string &InputFilePath : InputFilenames) {
for (const std::string &InputFilePath : InputFilePaths) {
Expected<std::unique_ptr<IFSStub>> StubOrErr = readInputFile(InputFilePath);
if (!StubOrErr) {
WithColor::error() << StubOrErr.takeError() << "\n";
return -1;
}
std::unique_ptr<IFSStub> TargetStub = std::move(StubOrErr.get());
if (!StubOrErr)
fatalError(StubOrErr.takeError());
if (Stub.Triple.empty()) {
PreviousInputFilePath = InputFilePath;
std::unique_ptr<IFSStub> TargetStub = std::move(StubOrErr.get());
if (PreviousInputFilePath.empty()) {
Stub.IfsVersion = TargetStub->IfsVersion;
Stub.Triple = TargetStub->Triple;
Stub.ObjectFileFormat = TargetStub->ObjectFileFormat;
Stub.SOName = TargetStub->SOName;
Stub.Target = TargetStub->Target;
Stub.SoName = TargetStub->SoName;
Stub.NeededLibs = TargetStub->NeededLibs;
} else {
Stub.ObjectFileFormat = !Stub.ObjectFileFormat.empty()
? Stub.ObjectFileFormat
: TargetStub->ObjectFileFormat;
if (Stub.IfsVersion != TargetStub->IfsVersion) {
if (Stub.IfsVersion.getMajor() != IFSVersionCurrent.getMajor()) {
if (Stub.IfsVersion.getMajor() != IfsVersionCurrent.getMajor()) {
WithColor::error()
<< "Interface Stub: IfsVersion Mismatch."
<< "\nFilenames: " << PreviousInputFilePath << " "
@ -479,29 +296,20 @@ int main(int argc, char *argv[]) {
if (TargetStub->IfsVersion > Stub.IfsVersion)
Stub.IfsVersion = TargetStub->IfsVersion;
}
if (Stub.ObjectFileFormat != TargetStub->ObjectFileFormat &&
!TargetStub->ObjectFileFormat.empty()) {
WithColor::error() << "Interface Stub: ObjectFileFormat Mismatch."
if (Stub.Target != TargetStub->Target && !TargetStub->Target.empty()) {
WithColor::error() << "Interface Stub: Target Mismatch."
<< "\nFilenames: " << PreviousInputFilePath << " "
<< InputFilePath << "\nObjectFileFormat Values: "
<< Stub.ObjectFileFormat << " "
<< TargetStub->ObjectFileFormat << "\n";
<< InputFilePath;
// << "\nTriple Values: " << Stub.Triple << " "
// << TargetStub->Triple << "\n";
return -1;
}
if (Stub.Triple != TargetStub->Triple && !TargetStub->Triple.empty()) {
WithColor::error() << "Interface Stub: Triple Mismatch."
if (Stub.SoName != TargetStub->SoName) {
WithColor::error() << "Interface Stub: SoName Mismatch."
<< "\nFilenames: " << PreviousInputFilePath << " "
<< InputFilePath
<< "\nTriple Values: " << Stub.Triple << " "
<< TargetStub->Triple << "\n";
return -1;
}
if (Stub.SOName != TargetStub->SOName) {
WithColor::error() << "Interface Stub: SOName Mismatch."
<< "\nFilenames: " << PreviousInputFilePath << " "
<< InputFilePath
<< "\nSOName Values: " << Stub.SOName << " "
<< TargetStub->SOName << "\n";
<< "\nSoName Values: " << Stub.SoName << " "
<< TargetStub->SoName << "\n";
return -1;
}
if (Stub.NeededLibs != TargetStub->NeededLibs) {
@ -549,16 +357,92 @@ int main(int argc, char *argv[]) {
PreviousInputFilePath = InputFilePath;
}
if (Stub.IfsVersion != IFSVersionCurrent)
if (Stub.IfsVersion.getMajor() != IFSVersionCurrent.getMajor()) {
if (Stub.IfsVersion != IfsVersionCurrent)
if (Stub.IfsVersion.getMajor() != IfsVersionCurrent.getMajor()) {
WithColor::error() << "Interface Stub: Bad IfsVersion: "
<< Stub.IfsVersion << ", llvm-ifs supported version: "
<< IFSVersionCurrent << ".\n";
<< IfsVersionCurrent << ".\n";
return -1;
}
for (auto &Entry : SymbolMap)
Stub.Symbols.push_back(Entry.second);
return writeIfso(Stub, (Action == "write-ifs"));
// Change SoName before emitting stubs.
if (SoName.getNumOccurrences() == 1)
Stub.SoName = SoName;
Optional<IFSArch> OverrideArch;
Optional<IFSEndiannessType> OverrideEndianness;
Optional<IFSBitWidthType> OverrideBitWidth;
Optional<std::string> OverrideTriple;
if (OptArch.getNumOccurrences() == 1)
OverrideArch = ELF::convertArchNameToEMachine(OptArch.getValue());
if (OptEndianness.getNumOccurrences() == 1)
OverrideEndianness = OptEndianness.getValue();
if (OptBitWidth.getNumOccurrences() == 1)
OverrideBitWidth = OptBitWidth.getValue();
if (OptTargetTriple.getNumOccurrences() == 1)
OverrideTriple = OptTargetTriple.getValue();
Error OverrideError = overrideIFSTarget(
Stub, OverrideArch, OverrideEndianness, OverrideBitWidth, OverrideTriple);
if (OverrideError)
fatalError(std::move(OverrideError));
switch (OutputFormat.getValue()) {
case FileFormat::TBD: {
std::error_code SysErr;
raw_fd_ostream Out(OutputFilePath, SysErr);
if (SysErr) {
WithColor::error() << "Couldn't open " << OutputFilePath
<< " for writing.\n";
return -1;
}
if (!Stub.Target.Triple) {
WithColor::error()
<< "Triple should be defined when output format is TBD";
return -1;
}
return writeTbdStub(llvm::Triple(Stub.Target.Triple.getValue()),
Stub.Symbols, "TBD", Out);
}
case FileFormat::IFS: {
Stub.IfsVersion = IfsVersionCurrent;
if (InputFormat.getValue() == FileFormat::ELF &&
OptTargetTripleHint.getNumOccurrences() == 1) {
std::error_code HintEC(1, std::generic_category());
IFSTarget HintTarget = parseTriple(OptTargetTripleHint);
if (Stub.Target.Arch.getValue() != HintTarget.Arch.getValue())
fatalError(make_error<StringError>(
"Triple hint does not match the actual architecture", HintEC));
if (Stub.Target.Endianness.getValue() !=
HintTarget.Endianness.getValue())
fatalError(make_error<StringError>(
"Triple hint does not match the actual endianness", HintEC));
if (Stub.Target.BitWidth.getValue() != HintTarget.BitWidth.getValue())
fatalError(make_error<StringError>(
"Triple hint does not match the actual bit width", HintEC));
stripIFSTarget(Stub, true, false, false, false);
Stub.Target.Triple = OptTargetTripleHint.getValue();
} else {
stripIFSTarget(Stub, StripIFSTarget, StripIFSArch,
StripIFSEndiannessWidth, StripIFSBitWidth);
}
Error IFSWriteError = writeIFS(OutputFilePath.getValue(), Stub);
if (IFSWriteError)
fatalError(std::move(IFSWriteError));
break;
}
case FileFormat::ELF: {
Error TargetError = validateIFSTarget(Stub, true);
if (TargetError)
fatalError(std::move(TargetError));
Error BinaryWriteError =
writeBinaryStub(OutputFilePath, Stub, WriteIfChanged);
if (BinaryWriteError)
fatalError(std::move(BinaryWriteError));
break;
}
}
return 0;
}

View File

@ -17,7 +17,7 @@
using namespace llvm;
using namespace llvm::ELF;
using namespace llvm::elfabi;
using namespace llvm::ifs;
void compareByLine(StringRef LHS, StringRef RHS) {
StringRef Line1;

View File

@ -246,7 +246,6 @@ group("test") {
"//llvm/tools/llvm-dis",
"//llvm/tools/llvm-dwarfdump",
"//llvm/tools/llvm-dwp",
"//llvm/tools/llvm-elfabi",
"//llvm/tools/llvm-exegesis",
"//llvm/tools/llvm-extract",
"//llvm/tools/llvm-gsymutil:llvm-gsymutil",

View File

@ -1,12 +0,0 @@
executable("llvm-elfabi") {
deps = [
"//llvm/lib/InterfaceStub",
"//llvm/lib/Object",
"//llvm/lib/Support",
"//llvm/lib/TextAPI",
]
sources = [
"ErrorCollector.cpp",
"llvm-elfabi.cpp",
]
}