Skip to content

Commit

Permalink
[ifs][elfabi] Merge llvm-ifs/elfabi tools
Browse files Browse the repository at this point in the history
This change merges llvm-elfabi and llvm-ifs tools.

Differential Revision: https://reviews.llvm.org/D100139
  • Loading branch information
zeroomega committed Jul 19, 2021
1 parent 61fa9af commit 6103fdf
Show file tree
Hide file tree
Showing 69 changed files with 380 additions and 758 deletions.
2 changes: 1 addition & 1 deletion clang/cmake/caches/Fuchsia-stage2.cmake
Expand Up @@ -246,7 +246,7 @@ set(LLVM_TOOLCHAIN_TOOLS
llvm-dlltool
llvm-dwarfdump
llvm-dwp
llvm-elfabi
llvm-ifs
llvm-gsymutil
llvm-lib
llvm-lipo
Expand Down
5 changes: 3 additions & 2 deletions clang/lib/Driver/ToolChains/InterfaceStubs.cpp
Expand Up @@ -20,10 +20,11 @@ void Merger::ConstructJob(Compilation &C, const JobAction &JA,
const llvm::opt::ArgList &Args,
const char *LinkingOutput) const {
std::string Merger = getToolChain().GetProgramPath(getShortName());
// TODO: Use IFS library directly in the future.
llvm::opt::ArgStringList CmdArgs;
CmdArgs.push_back("-action");
CmdArgs.push_back("--input-format=IFS");
const bool WriteBin = !Args.getLastArg(options::OPT_emit_merged_ifs);
CmdArgs.push_back(WriteBin ? "write-bin" : "write-ifs");
CmdArgs.push_back(WriteBin ? "--output-format=ELF" : "--output-format=IFS");
CmdArgs.push_back("-o");

// Normally we want to write to a side-car file ending in ".ifso" so for
Expand Down
2 changes: 1 addition & 1 deletion clang/test/InterfaceStubs/driver-test.c
Expand Up @@ -12,7 +12,7 @@
// RUN: %clang -target x86_64-unknown-linux-gnu -x c -S \
// RUN: -fno-integrated-cc1 \
// RUN: -emit-interface-stubs %s %S/object.c %S/weak.cpp && \
// RUN: llvm-nm %t/a.out.ifso 2>&1 | FileCheck --check-prefix=CHECK-IFS %s
// RUN: llvm-nm -D %t/a.out.ifso 2>&1 | FileCheck --check-prefix=CHECK-IFS %s

// CHECK-IFS-DAG: data
// CHECK-IFS-DAG: foo
Expand Down
4 changes: 2 additions & 2 deletions llvm/include/llvm/InterfaceStub/ELFObjHandler.h
Expand Up @@ -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);
Expand All @@ -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
4 changes: 2 additions & 2 deletions llvm/include/llvm/InterfaceStub/IFSHandler.h
Expand Up @@ -26,7 +26,7 @@ class raw_ostream;
class Error;
class StringRef;

namespace elfabi {
namespace ifs {

struct IFSStub;

Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions llvm/include/llvm/InterfaceStub/IFSStub.h
Expand Up @@ -20,7 +20,7 @@
#include <vector>

namespace llvm {
namespace elfabi {
namespace ifs {

typedef uint16_t IFSArch;

Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions llvm/lib/InterfaceStub/ELFObjHandler.cpp
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
24 changes: 12 additions & 12 deletions llvm/lib/InterfaceStub/IFSHandler.cpp
Expand Up @@ -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)

Expand Down Expand Up @@ -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)) {
Expand All @@ -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));
Expand All @@ -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) {
Expand All @@ -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 &&
Expand Down Expand Up @@ -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 ||
Expand Down Expand Up @@ -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.
Expand All @@ -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();
Expand Down
14 changes: 7 additions & 7 deletions llvm/lib/InterfaceStub/IFSStub.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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:
Expand Down
1 change: 0 additions & 1 deletion llvm/test/CMakeLists.txt
Expand Up @@ -77,7 +77,6 @@ set(LLVM_TEST_DEPENDS
dsymutil
llvm-dwarfdump
llvm-dwp
llvm-elfabi
llvm-exegesis
llvm-extract
llvm-gsymutil
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/tools/llvm-ifs/binary-read-add-soname.test
@@ -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:
Expand Down
10 changes: 5 additions & 5 deletions llvm/test/tools/llvm-ifs/binary-read-arch.test
@@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion llvm/test/tools/llvm-ifs/binary-read-bad-soname.test
@@ -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:
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/tools/llvm-ifs/binary-read-bad-vaddr.test
@@ -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:
Expand Down
@@ -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:
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/tools/llvm-ifs/binary-read-neededlibs.test
@@ -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:
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/tools/llvm-ifs/binary-read-no-dt-strsz.test
@@ -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:
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/tools/llvm-ifs/binary-read-no-dt-strtab.test
@@ -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:
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/tools/llvm-ifs/binary-read-no-dynamic.test
@@ -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:
Expand Down
4 changes: 2 additions & 2 deletions llvm/test/tools/llvm-ifs/binary-read-replace-soname.test
@@ -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:
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/tools/llvm-ifs/binary-read-soname-no-null.test
@@ -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:
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/tools/llvm-ifs/binary-read-soname.test
@@ -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:
Expand Down
12 changes: 6 additions & 6 deletions llvm/test/tools/llvm-ifs/binary-read-syms-gnu-hash.test
@@ -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
Expand All @@ -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: 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: _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: _Z11rotateArrayPii, Type: Func }
# CHECK-NEXT: - { Name: _init, Type: Func }
# CHECK-NEXT: ...

0 comments on commit 6103fdf

Please sign in to comment.