diff --git a/clang/cmake/caches/Fuchsia-stage2.cmake b/clang/cmake/caches/Fuchsia-stage2.cmake --- a/clang/cmake/caches/Fuchsia-stage2.cmake +++ b/clang/cmake/caches/Fuchsia-stage2.cmake @@ -246,7 +246,7 @@ llvm-dlltool llvm-dwarfdump llvm-dwp - llvm-elfabi + llvm-ifs llvm-gsymutil llvm-lib llvm-lipo diff --git a/clang/lib/Driver/ToolChains/InterfaceStubs.cpp b/clang/lib/Driver/ToolChains/InterfaceStubs.cpp --- a/clang/lib/Driver/ToolChains/InterfaceStubs.cpp +++ b/clang/lib/Driver/ToolChains/InterfaceStubs.cpp @@ -20,10 +20,11 @@ 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 diff --git a/clang/test/InterfaceStubs/driver-test.c b/clang/test/InterfaceStubs/driver-test.c --- a/clang/test/InterfaceStubs/driver-test.c +++ b/clang/test/InterfaceStubs/driver-test.c @@ -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 diff --git a/llvm/include/llvm/InterfaceStub/ELFObjHandler.h b/llvm/include/llvm/InterfaceStub/ELFObjHandler.h --- a/llvm/include/llvm/InterfaceStub/ELFObjHandler.h +++ b/llvm/include/llvm/InterfaceStub/ELFObjHandler.h @@ -22,7 +22,7 @@ class MemoryBuffer; -namespace elfabi { +namespace ifs { /// Attempt to read a binary ELF file from a MemoryBuffer. Expected> readELFFile(MemoryBufferRef Buf); @@ -38,7 +38,7 @@ Error writeBinaryStub(StringRef FilePath, const IFSStub &Stub, bool WriteIfChanged = false); -} // end namespace elfabi +} // end namespace ifs } // end namespace llvm #endif // LLVM_INTERFACESTUB_ELFOBJHANDLER_H diff --git a/llvm/include/llvm/InterfaceStub/IFSHandler.h b/llvm/include/llvm/InterfaceStub/IFSHandler.h --- a/llvm/include/llvm/InterfaceStub/IFSHandler.h +++ b/llvm/include/llvm/InterfaceStub/IFSHandler.h @@ -26,7 +26,7 @@ class Error; class StringRef; -namespace elfabi { +namespace ifs { struct IFSStub; @@ -54,7 +54,7 @@ /// 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 diff --git a/llvm/include/llvm/InterfaceStub/IFSStub.h b/llvm/include/llvm/InterfaceStub/IFSStub.h --- a/llvm/include/llvm/InterfaceStub/IFSStub.h +++ b/llvm/include/llvm/InterfaceStub/IFSStub.h @@ -20,7 +20,7 @@ #include namespace llvm { -namespace elfabi { +namespace ifs { typedef uint16_t IFSArch; @@ -151,7 +151,7 @@ /// /// @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 diff --git a/llvm/lib/InterfaceStub/ELFObjHandler.cpp b/llvm/lib/InterfaceStub/ELFObjHandler.cpp --- a/llvm/lib/InterfaceStub/ELFObjHandler.cpp +++ b/llvm/lib/InterfaceStub/ELFObjHandler.cpp @@ -27,7 +27,7 @@ using namespace llvm::ELF; namespace llvm { -namespace elfabi { +namespace ifs { // Simple struct to hold relevant .dynamic entries. struct DynamicEntries { @@ -671,5 +671,5 @@ llvm_unreachable("invalid binary output target"); } -} // namespace elfabi +} // end namespace ifs } // end namespace llvm diff --git a/llvm/lib/InterfaceStub/IFSHandler.cpp b/llvm/lib/InterfaceStub/IFSHandler.cpp --- a/llvm/lib/InterfaceStub/IFSHandler.cpp +++ b/llvm/lib/InterfaceStub/IFSHandler.cpp @@ -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 @@ return true; } -Expected> elfabi::readIFSFromBuffer(StringRef Buf) { +Expected> ifs::readIFSFromBuffer(StringRef Buf) { yaml::Input YamlIn(Buf); std::unique_ptr Stub(new IFSStubTriple()); if (usesTriple(Buf)) { @@ -183,7 +183,7 @@ return createStringError(Err, "YAML failed reading as IFS"); } - if (Stub->IfsVersion > elfabi::IFSVersionCurrent) + if (Stub->IfsVersion > IFSVersionCurrent) return make_error( "IFS version " + Stub->IfsVersion.getAsString() + " is unsupported.", std::make_error_code(std::errc::invalid_argument)); @@ -194,7 +194,7 @@ 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 CopyStub(new IFSStubTriple(Stub)); if (Stub.Target.Arch) { @@ -212,10 +212,10 @@ return Error::success(); } -Error elfabi::overrideIFSTarget(IFSStub &Stub, Optional OverrideArch, - Optional OverrideEndianness, - Optional OverrideBitWidth, - Optional OverrideTriple) { +Error ifs::overrideIFSTarget(IFSStub &Stub, Optional OverrideArch, + Optional OverrideEndianness, + Optional OverrideBitWidth, + Optional OverrideTriple) { std::error_code OverrideEC(1, std::generic_category()); if (OverrideArch) { if (Stub.Target.Arch && @@ -252,7 +252,7 @@ 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 @@ 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 @@ 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(); diff --git a/llvm/lib/InterfaceStub/IFSStub.cpp b/llvm/lib/InterfaceStub/IFSStub.cpp --- a/llvm/lib/InterfaceStub/IFSStub.cpp +++ b/llvm/lib/InterfaceStub/IFSStub.cpp @@ -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 @@ !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::convertIFSEndiannessToELF(IFSEndiannessType Endianness) { +uint8_t ifs::convertIFSEndiannessToELF(IFSEndiannessType Endianness) { switch (Endianness) { case IFSEndiannessType::Little: return ELF::ELFDATA2LSB; @@ -80,7 +80,7 @@ } } -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 @@ } } -IFSBitWidthType elfabi::convertELFBitWidthToIFS(uint8_t BitWidth) { +IFSBitWidthType ifs::convertELFBitWidthToIFS(uint8_t BitWidth) { switch (BitWidth) { case ELF::ELFCLASS32: return IFSBitWidthType::IFS32; @@ -105,7 +105,7 @@ } } -IFSEndiannessType elfabi::convertELFEndiannessToIFS(uint8_t Endianness) { +IFSEndiannessType ifs::convertELFEndiannessToIFS(uint8_t Endianness) { switch (Endianness) { case ELF::ELFDATA2LSB: return IFSEndiannessType::Little; @@ -116,7 +116,7 @@ } } -IFSSymbolType elfabi::convertELFSymbolTypeToIFS(uint8_t SymbolType) { +IFSSymbolType ifs::convertELFSymbolTypeToIFS(uint8_t SymbolType) { SymbolType = SymbolType & 0xf; switch (SymbolType) { case ELF::STT_OBJECT: diff --git a/llvm/test/CMakeLists.txt b/llvm/test/CMakeLists.txt --- a/llvm/test/CMakeLists.txt +++ b/llvm/test/CMakeLists.txt @@ -77,7 +77,6 @@ dsymutil llvm-dwarfdump llvm-dwp - llvm-elfabi llvm-exegesis llvm-extract llvm-gsymutil diff --git a/llvm/test/tools/llvm-ifs/binary-read-add-soname.test b/llvm/test/tools/llvm-ifs/binary-read-add-soname.test --- a/llvm/test/tools/llvm-ifs/binary-read-add-soname.test +++ b/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: diff --git a/llvm/test/tools/llvm-ifs/binary-read-arch.test b/llvm/test/tools/llvm-ifs/binary-read-arch.test --- a/llvm/test/tools/llvm-ifs/binary-read-arch.test +++ b/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: @@ -52,7 +52,7 @@ # 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 @@ 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 @@ 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 diff --git a/llvm/test/tools/llvm-ifs/binary-read-bad-soname.test b/llvm/test/tools/llvm-ifs/binary-read-bad-soname.test --- a/llvm/test/tools/llvm-ifs/binary-read-bad-soname.test +++ b/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: diff --git a/llvm/test/tools/llvm-ifs/binary-read-bad-vaddr.test b/llvm/test/tools/llvm-ifs/binary-read-bad-vaddr.test --- a/llvm/test/tools/llvm-ifs/binary-read-bad-vaddr.test +++ b/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: diff --git a/llvm/test/tools/llvm-ifs/binary-read-neededlibs-bad-offset.test b/llvm/test/tools/llvm-ifs/binary-read-neededlibs-bad-offset.test --- a/llvm/test/tools/llvm-ifs/binary-read-neededlibs-bad-offset.test +++ b/llvm/test/tools/llvm-ifs/binary-read-neededlibs-bad-offset.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: diff --git a/llvm/test/tools/llvm-ifs/binary-read-neededlibs.test b/llvm/test/tools/llvm-ifs/binary-read-neededlibs.test --- a/llvm/test/tools/llvm-ifs/binary-read-neededlibs.test +++ b/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: diff --git a/llvm/test/tools/llvm-ifs/binary-read-no-dt-strsz.test b/llvm/test/tools/llvm-ifs/binary-read-no-dt-strsz.test --- a/llvm/test/tools/llvm-ifs/binary-read-no-dt-strsz.test +++ b/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: diff --git a/llvm/test/tools/llvm-ifs/binary-read-no-dt-strtab.test b/llvm/test/tools/llvm-ifs/binary-read-no-dt-strtab.test --- a/llvm/test/tools/llvm-ifs/binary-read-no-dt-strtab.test +++ b/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: diff --git a/llvm/test/tools/llvm-ifs/binary-read-no-dynamic.test b/llvm/test/tools/llvm-ifs/binary-read-no-dynamic.test --- a/llvm/test/tools/llvm-ifs/binary-read-no-dynamic.test +++ b/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: diff --git a/llvm/test/tools/llvm-ifs/binary-read-replace-soname.test b/llvm/test/tools/llvm-ifs/binary-read-replace-soname.test --- a/llvm/test/tools/llvm-ifs/binary-read-replace-soname.test +++ b/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: diff --git a/llvm/test/tools/llvm-ifs/binary-read-soname-no-null.test b/llvm/test/tools/llvm-ifs/binary-read-soname-no-null.test --- a/llvm/test/tools/llvm-ifs/binary-read-soname-no-null.test +++ b/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: diff --git a/llvm/test/tools/llvm-ifs/binary-read-soname.test b/llvm/test/tools/llvm-ifs/binary-read-soname.test --- a/llvm/test/tools/llvm-ifs/binary-read-soname.test +++ b/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: diff --git a/llvm/test/tools/llvm-ifs/binary-read-syms-gnu-hash.test b/llvm/test/tools/llvm-ifs/binary-read-syms-gnu-hash.test --- a/llvm/test/tools/llvm-ifs/binary-read-syms-gnu-hash.test +++ b/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 @@ -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: ... diff --git a/llvm/test/tools/llvm-ifs/binary-read-syms-sysv-hash.test b/llvm/test/tools/llvm-ifs/binary-read-syms-sysv-hash.test --- a/llvm/test/tools/llvm-ifs/binary-read-syms-sysv-hash.test +++ b/llvm/test/tools/llvm-ifs/binary-read-syms-sysv-hash.test @@ -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: ... diff --git a/llvm/test/tools/llvm-ifs/conflict-header-triple.ifs b/llvm/test/tools/llvm-ifs/conflict-header-triple.ifs --- a/llvm/test/tools/llvm-ifs/conflict-header-triple.ifs +++ b/llvm/test/tools/llvm-ifs/conflict-header-triple.ifs @@ -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 diff --git a/llvm/test/tools/llvm-ifs/conflict-header-version.ifs b/llvm/test/tools/llvm-ifs/conflict-header-version.ifs --- a/llvm/test/tools/llvm-ifs/conflict-header-version.ifs +++ b/llvm/test/tools/llvm-ifs/conflict-header-version.ifs @@ -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. diff --git a/llvm/test/tools/llvm-ifs/conflict-size.ifs b/llvm/test/tools/llvm-ifs/conflict-size.ifs --- a/llvm/test/tools/llvm-ifs/conflict-size.ifs +++ b/llvm/test/tools/llvm-ifs/conflict-size.ifs @@ -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 diff --git a/llvm/test/tools/llvm-ifs/conflict-type.ifs b/llvm/test/tools/llvm-ifs/conflict-type.ifs --- a/llvm/test/tools/llvm-ifs/conflict-type.ifs +++ b/llvm/test/tools/llvm-ifs/conflict-type.ifs @@ -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 diff --git a/llvm/test/tools/llvm-ifs/conflict-weak.ifs b/llvm/test/tools/llvm-ifs/conflict-weak.ifs --- a/llvm/test/tools/llvm-ifs/conflict-weak.ifs +++ b/llvm/test/tools/llvm-ifs/conflict-weak.ifs @@ -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: diff --git a/llvm/test/tools/llvm-ifs/default-empty.ifs b/llvm/test/tools/llvm-ifs/default-empty.ifs --- a/llvm/test/tools/llvm-ifs/default-empty.ifs +++ b/llvm/test/tools/llvm-ifs/default-empty.ifs @@ -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: [] ... diff --git a/llvm/test/tools/llvm-ifs/empty1.ifs b/llvm/test/tools/llvm-ifs/empty1.ifs --- a/llvm/test/tools/llvm-ifs/empty1.ifs +++ b/llvm/test/tools/llvm-ifs/empty1.ifs @@ -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 diff --git a/llvm/test/tools/llvm-ifs/empty2.ifs b/llvm/test/tools/llvm-ifs/empty2.ifs --- a/llvm/test/tools/llvm-ifs/empty2.ifs +++ b/llvm/test/tools/llvm-ifs/empty2.ifs @@ -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 diff --git a/llvm/test/tools/llvm-ifs/fail-file-open.test b/llvm/test/tools/llvm-ifs/fail-file-open.test --- a/llvm/test/tools/llvm-ifs/fail-file-open.test +++ b/llvm/test/tools/llvm-ifs/fail-file-open.test @@ -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` diff --git a/llvm/test/tools/llvm-ifs/fail-file-write-windows.test b/llvm/test/tools/llvm-ifs/fail-file-write-windows.test --- a/llvm/test/tools/llvm-ifs/fail-file-write-windows.test +++ b/llvm/test/tools/llvm-ifs/fail-file-write-windows.test @@ -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 diff --git a/llvm/test/tools/llvm-ifs/fail-file-write.test b/llvm/test/tools/llvm-ifs/fail-file-write.test --- a/llvm/test/tools/llvm-ifs/fail-file-write.test +++ b/llvm/test/tools/llvm-ifs/fail-file-write.test @@ -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 diff --git a/llvm/test/tools/llvm-ifs/func.ifs b/llvm/test/tools/llvm-ifs/func.ifs --- a/llvm/test/tools/llvm-ifs/func.ifs +++ b/llvm/test/tools/llvm-ifs/func.ifs @@ -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 diff --git a/llvm/test/tools/llvm-ifs/ifs-emits-current-version.test b/llvm/test/tools/llvm-ifs/ifs-emits-current-version.test --- a/llvm/test/tools/llvm-ifs/ifs-emits-current-version.test +++ b/llvm/test/tools/llvm-ifs/ifs-emits-current-version.test @@ -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 diff --git a/llvm/test/tools/llvm-ifs/ifs-read-basic.test b/llvm/test/tools/llvm-ifs/ifs-read-basic.test --- a/llvm/test/tools/llvm-ifs/ifs-read-basic.test +++ b/llvm/test/tools/llvm-ifs/ifs-read-basic.test @@ -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 @@ # 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: ... diff --git a/llvm/test/tools/llvm-ifs/ios-tbd.ifs b/llvm/test/tools/llvm-ifs/ios-tbd.ifs --- a/llvm/test/tools/llvm-ifs/ios-tbd.ifs +++ b/llvm/test/tools/llvm-ifs/ios-tbd.ifs @@ -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 ] diff --git a/llvm/test/tools/llvm-ifs/macos-tbd.ifs b/llvm/test/tools/llvm-ifs/macos-tbd.ifs --- a/llvm/test/tools/llvm-ifs/macos-tbd.ifs +++ b/llvm/test/tools/llvm-ifs/macos-tbd.ifs @@ -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 ] diff --git a/llvm/test/tools/llvm-ifs/object-function-size-weak-combo.ifs b/llvm/test/tools/llvm-ifs/object-function-size-weak-combo.ifs --- a/llvm/test/tools/llvm-ifs/object-function-size-weak-combo.ifs +++ b/llvm/test/tools/llvm-ifs/object-function-size-weak-combo.ifs @@ -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 diff --git a/llvm/test/tools/llvm-ifs/object.ifs b/llvm/test/tools/llvm-ifs/object.ifs --- a/llvm/test/tools/llvm-ifs/object.ifs +++ b/llvm/test/tools/llvm-ifs/object.ifs @@ -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 diff --git a/llvm/test/tools/llvm-ifs/output-target-error.test b/llvm/test/tools/llvm-ifs/output-target-error.test --- a/llvm/test/tools/llvm-ifs/output-target-error.test +++ b/llvm/test/tools/llvm-ifs/output-target-error.test @@ -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 @@ 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'! diff --git a/llvm/test/tools/llvm-ifs/preserve-dates-ifs.test b/llvm/test/tools/llvm-ifs/preserve-dates-ifs.test --- a/llvm/test/tools/llvm-ifs/preserve-dates-ifs.test +++ b/llvm/test/tools/llvm-ifs/preserve-dates-ifs.test @@ -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}} diff --git a/llvm/test/tools/llvm-ifs/preserve-dates-stub.test b/llvm/test/tools/llvm-ifs/preserve-dates-stub.test --- a/llvm/test/tools/llvm-ifs/preserve-dates-stub.test +++ b/llvm/test/tools/llvm-ifs/preserve-dates-stub.test @@ -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 diff --git a/llvm/test/tools/llvm-ifs/read-elf-dynsym.test b/llvm/test/tools/llvm-ifs/read-elf-dynsym.test --- a/llvm/test/tools/llvm-ifs/read-elf-dynsym.test +++ b/llvm/test/tools/llvm-ifs/read-elf-dynsym.test @@ -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 diff --git a/llvm/test/tools/llvm-ifs/read-ifs-as-elf.test b/llvm/test/tools/llvm-ifs/read-ifs-as-elf.test --- a/llvm/test/tools/llvm-ifs/read-ifs-as-elf.test +++ b/llvm/test/tools/llvm-ifs/read-ifs-as-elf.test @@ -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 diff --git a/llvm/test/tools/llvm-ifs/read-ifs-as-ifs.test b/llvm/test/tools/llvm-ifs/read-ifs-as-ifs.test --- a/llvm/test/tools/llvm-ifs/read-ifs-as-ifs.test +++ b/llvm/test/tools/llvm-ifs/read-ifs-as-ifs.test @@ -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 diff --git a/llvm/test/tools/llvm-ifs/read-ifs-with-bad-bitwidth.test b/llvm/test/tools/llvm-ifs/read-ifs-with-bad-bitwidth.test --- a/llvm/test/tools/llvm-ifs/read-ifs-with-bad-bitwidth.test +++ b/llvm/test/tools/llvm-ifs/read-ifs-with-bad-bitwidth.test @@ -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 diff --git a/llvm/test/tools/llvm-ifs/read-ifs-with-bad-endianness.test b/llvm/test/tools/llvm-ifs/read-ifs-with-bad-endianness.test --- a/llvm/test/tools/llvm-ifs/read-ifs-with-bad-endianness.test +++ b/llvm/test/tools/llvm-ifs/read-ifs-with-bad-endianness.test @@ -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 diff --git a/llvm/test/tools/llvm-ifs/read-unsupported-file.test b/llvm/test/tools/llvm-ifs/read-unsupported-file.test --- a/llvm/test/tools/llvm-ifs/read-unsupported-file.test +++ b/llvm/test/tools/llvm-ifs/read-unsupported-file.test @@ -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 diff --git a/llvm/test/tools/llvm-ifs/strip-target.test b/llvm/test/tools/llvm-ifs/strip-target.test --- a/llvm/test/tools/llvm-ifs/strip-target.test +++ b/llvm/test/tools/llvm-ifs/strip-target.test @@ -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 diff --git a/llvm/test/tools/llvm-ifs/strong.ifs b/llvm/test/tools/llvm-ifs/strong.ifs --- a/llvm/test/tools/llvm-ifs/strong.ifs +++ b/llvm/test/tools/llvm-ifs/strong.ifs @@ -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 diff --git a/llvm/test/tools/llvm-ifs/tvos-tbd.ifs b/llvm/test/tools/llvm-ifs/tvos-tbd.ifs --- a/llvm/test/tools/llvm-ifs/tvos-tbd.ifs +++ b/llvm/test/tools/llvm-ifs/tvos-tbd.ifs @@ -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 ] diff --git a/llvm/test/tools/llvm-ifs/version-ok.ifs b/llvm/test/tools/llvm-ifs/version-ok.ifs --- a/llvm/test/tools/llvm-ifs/version-ok.ifs +++ b/llvm/test/tools/llvm-ifs/version-ok.ifs @@ -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 diff --git a/llvm/test/tools/llvm-ifs/watchos-tbd.ifs b/llvm/test/tools/llvm-ifs/watchos-tbd.ifs --- a/llvm/test/tools/llvm-ifs/watchos-tbd.ifs +++ b/llvm/test/tools/llvm-ifs/watchos-tbd.ifs @@ -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 ] diff --git a/llvm/test/tools/llvm-ifs/weak-mismatch.ifs b/llvm/test/tools/llvm-ifs/weak-mismatch.ifs --- a/llvm/test/tools/llvm-ifs/weak-mismatch.ifs +++ b/llvm/test/tools/llvm-ifs/weak-mismatch.ifs @@ -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: diff --git a/llvm/test/tools/llvm-ifs/weak.ifs b/llvm/test/tools/llvm-ifs/weak.ifs --- a/llvm/test/tools/llvm-ifs/weak.ifs +++ b/llvm/test/tools/llvm-ifs/weak.ifs @@ -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 diff --git a/llvm/test/tools/llvm-ifs/write-stub-no-nonlocal-symbol.test b/llvm/test/tools/llvm-ifs/write-stub-no-nonlocal-symbol.test --- a/llvm/test/tools/llvm-ifs/write-stub-no-nonlocal-symbol.test +++ b/llvm/test/tools/llvm-ifs/write-stub-no-nonlocal-symbol.test @@ -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 diff --git a/llvm/test/tools/llvm-ifs/write-stub.test b/llvm/test/tools/llvm-ifs/write-stub.test --- a/llvm/test/tools/llvm-ifs/write-stub.test +++ b/llvm/test/tools/llvm-ifs/write-stub.test @@ -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 diff --git a/llvm/tools/llvm-elfabi/CMakeLists.txt b/llvm/tools/llvm-elfabi/CMakeLists.txt deleted file mode 100644 --- a/llvm/tools/llvm-elfabi/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -set(LLVM_LINK_COMPONENTS - BinaryFormat - InterfaceStub - Object - Support - TextAPI - ) - -add_llvm_tool(llvm-elfabi - ErrorCollector.cpp - llvm-elfabi.cpp - ) diff --git a/llvm/tools/llvm-elfabi/llvm-elfabi.cpp b/llvm/tools/llvm-elfabi/llvm-elfabi.cpp deleted file mode 100644 --- a/llvm/tools/llvm-elfabi/llvm-elfabi.cpp +++ /dev/null @@ -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 - -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 InputFilePath(cl::Positional, cl::desc("input"), - cl::Required); -cl::opt 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 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 OptArch("arch", - cl::desc("Specify the architecture, e.g. x86_64")); -cl::opt OptBitWidth( - "bitwidth", cl::desc("Specify the bit width"), - cl::values(clEnumValN(IFSBitWidthType::IFS32, "32", "32 bits"), - clEnumValN(IFSBitWidthType::IFS64, "64", "64 bits"))); -cl::opt OptEndianness( - "endianness", cl::desc("Specify the endianness"), - cl::values(clEnumValN(IFSEndiannessType::Little, "little", "Little Endian"), - clEnumValN(IFSEndiannessType::Big, "big", "Big Endian"))); -cl::opt OptTargetTriple( - "target", cl::desc("Specify the target triple, e.g. x86_64-linux-gnu")); -cl::opt OptTargetTripleHint( - "hint-ifs-target", - cl::desc("When --output-format is 'IFS', this flag will hint the expected " - "target triple for IFS output")); -cl::opt StripIFSArch( - "strip-ifs-arch", - cl::desc("Strip target architecture information away from IFS output")); -cl::opt StripIFSBitWidth( - "strip-ifs-bitwidth", - cl::desc("Strip target bit width information away from IFS output")); -cl::opt StripIFSEndiannessWidth( - "strip-ifs-endianness", - cl::desc("Strip target endianness information away from IFS output")); -cl::opt StripIFSTarget( - "strip-ifs-target", - cl::desc("Strip all target information away from IFS output")); -cl::opt - SOName("soname", - cl::desc("Manually set the DT_SONAME entry of any emitted files"), - cl::value_desc("name")); -cl::opt OutputFilePath("output", cl::desc("Output file")); -cl::opt 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> 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> readInputFile(StringRef FilePath) { - // Read in file. - ErrorOr> BufOrError = - MemoryBuffer::getFile(FilePath); - if (!BufOrError) { - return createStringError(BufOrError.getError(), "Could not open `%s`", - FilePath.data()); - } - - std::unique_ptr 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> 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> 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> StubOrErr = readInputFile(InputFilePath); - if (!StubOrErr) - fatalError(StubOrErr.takeError()); - - std::unique_ptr TargetStub = std::move(StubOrErr.get()); - - // Change SoName before emitting stubs. - if (SOName.getNumOccurrences() == 1) - TargetStub->SoName = SOName; - Optional OverrideArch; - Optional OverrideEndianness; - Optional OverrideBitWidth; - Optional 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( - "Triple hint does not match the actual architecture", HintEC)); - } - if (TargetStub->Target.Endianness.getValue() != - HintTarget.Endianness.getValue()) { - fatalError(make_error( - "Triple hint does not match the actual endianness", HintEC)); - } - if (TargetStub->Target.BitWidth.getValue() != - HintTarget.BitWidth.getValue()) { - fatalError(make_error( - "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; - } - } -} diff --git a/llvm/tools/llvm-ifs/CMakeLists.txt b/llvm/tools/llvm-ifs/CMakeLists.txt --- a/llvm/tools/llvm-ifs/CMakeLists.txt +++ b/llvm/tools/llvm-ifs/CMakeLists.txt @@ -7,5 +7,6 @@ ) add_llvm_tool(llvm-ifs + ErrorCollector.cpp llvm-ifs.cpp ) diff --git a/llvm/tools/llvm-elfabi/ErrorCollector.h b/llvm/tools/llvm-ifs/ErrorCollector.h rename from llvm/tools/llvm-elfabi/ErrorCollector.h rename to llvm/tools/llvm-ifs/ErrorCollector.h --- a/llvm/tools/llvm-elfabi/ErrorCollector.h +++ b/llvm/tools/llvm-ifs/ErrorCollector.h @@ -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 namespace llvm { -namespace elfabi { +namespace ifs { class ErrorCollector { public: @@ -68,7 +68,7 @@ std::vector Tags; }; -} // end namespace elfabi +} // end namespace ifs } // end namespace llvm -#endif // LLVM_TOOLS_ELFABI_ERRORCOLLECTOR_H +#endif // LLVM_TOOLS_LLVM_IFS_ERRORCOLLECTOR_H diff --git a/llvm/tools/llvm-elfabi/ErrorCollector.cpp b/llvm/tools/llvm-ifs/ErrorCollector.cpp rename from llvm/tools/llvm-elfabi/ErrorCollector.cpp rename to llvm/tools/llvm-ifs/ErrorCollector.cpp --- a/llvm/tools/llvm-elfabi/ErrorCollector.cpp +++ b/llvm/tools/llvm-ifs/ErrorCollector.cpp @@ -14,7 +14,7 @@ #include using namespace llvm; -using namespace llvm::elfabi; +using namespace llvm::ifs; void ErrorCollector::escalateToFatal() { ErrorsAreFatal = true; } diff --git a/llvm/tools/llvm-ifs/llvm-ifs.cpp b/llvm/tools/llvm-ifs/llvm-ifs.cpp --- a/llvm/tools/llvm-ifs/llvm-ifs.cpp +++ b/llvm/tools/llvm-ifs/llvm-ifs.cpp @@ -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); -} // end anonymous namespace - -static cl::opt Action("action", cl::desc(""), - cl::value_desc("write-ifs | write-bin"), - cl::init("write-ifs")); - -static cl::opt ForceFormat("force-format", - cl::desc(""), - cl::value_desc("ELF | TBD"), - cl::init("")); +const VersionTuple IfsVersionCurrent(3, 0); -static cl::list InputFilenames(cl::Positional, - cl::desc(""), - cl::ZeroOrMore); - -static cl::opt OutputFilename("o", cl::desc(""), - cl::value_desc("path")); - -static cl::opt UseInterfaceStub( - "use-interfacestub", - cl::desc("Write output ELF file using latest InterfaceStub backend"), - cl::init(false)); +enum class FileFormat { IFS, ELF, TBD }; +} // end anonymous namespace -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 InputFilePaths(cl::Positional, cl::desc("input"), + cl::ZeroOrMore); +cl::opt 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 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 OptArch("arch", + cl::desc("Specify the architecture, e.g. x86_64")); +cl::opt OptBitWidth( + "bitwidth", cl::desc("Specify the bit width"), + cl::values(clEnumValN(IFSBitWidthType::IFS32, "32", "32 bits"), + clEnumValN(IFSBitWidthType::IFS64, "64", "64 bits"))); +cl::opt OptEndianness( + "endianness", cl::desc("Specify the endianness"), + cl::values(clEnumValN(IFSEndiannessType::Little, "little", "Little Endian"), + clEnumValN(IFSEndiannessType::Big, "big", "Big Endian"))); +cl::opt OptTargetTriple( + "target", cl::desc("Specify the target triple, e.g. x86_64-linux-gnu")); +cl::opt OptTargetTripleHint( + "hint-ifs-target", + cl::desc("When --output-format is 'IFS', this flag will hint the expected " + "target triple for IFS output")); +cl::opt StripIFSArch( + "strip-ifs-arch", + cl::desc("Strip target architecture information away from IFS output")); +cl::opt StripIFSBitWidth( + "strip-ifs-bitwidth", + cl::desc("Strip target bit width information away from IFS output")); +cl::opt StripIFSEndiannessWidth( + "strip-ifs-endianness", + cl::desc("Strip target endianness information away from IFS output")); +cl::opt StripIFSTarget( + "strip-ifs-target", + cl::desc("Strip all target information away from IFS output")); +cl::opt + SoName("soname", + cl::desc("Manually set the DT_SONAME entry of any emitted files"), + cl::value_desc("name")); +cl::opt OutputFilePath("output", cl::desc("Output file")); +cl::alias OutputFilePathA("o", cl::desc("Alias for --output"), + cl::aliasopt(OutputFilePath)); +cl::opt 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 @@ 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 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 { - 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 { - 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 SOName; - std::vector NeededLibs; - std::vector 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 { - 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> readInputFile(StringRef FilePath) { // Read in file. ErrorOr> BufOrError = @@ -189,19 +123,46 @@ FilePath.data()); std::unique_ptr FileReadBuffer = std::move(*BufOrError); - yaml::Input YamlIn(FileReadBuffer->getBuffer()); - std::unique_ptr Stub(new IFSStub()); - YamlIn >> *Stub; - - if (std::error_code Err = YamlIn.error()) - return createStringError(Err, "Failed reading Interface Stub File."); + ErrorCollector EC(/*UseFatalErrors=*/false); + + // First try to read as a binary (fails fast if not binary). + if (InputFormat.getNumOccurrences() == 0 || InputFormat == FileFormat::ELF) { + Expected> 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( - "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> 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 &Symbols, @@ -220,10 +181,6 @@ 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 @@ return 0; } -static int writeElfStub(const Triple &T, const std::vector &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(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> 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(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: -// ObjectFileFormat: -// Symbols: -// _ZSymbolName: { 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 SymbolMap; - std::string PreviousInputFilePath; - for (const std::string &InputFilePath : InputFilenames) { + for (const std::string &InputFilePath : InputFilePaths) { Expected> StubOrErr = readInputFile(InputFilePath); - if (!StubOrErr) { - WithColor::error() << StubOrErr.takeError() << "\n"; - return -1; - } - std::unique_ptr TargetStub = std::move(StubOrErr.get()); + if (!StubOrErr) + fatalError(StubOrErr.takeError()); - if (Stub.Triple.empty()) { - PreviousInputFilePath = InputFilePath; + std::unique_ptr 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 @@ 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 @@ 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 OverrideArch; + Optional OverrideEndianness; + Optional OverrideBitWidth; + Optional 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( + "Triple hint does not match the actual architecture", HintEC)); + if (Stub.Target.Endianness.getValue() != + HintTarget.Endianness.getValue()) + fatalError(make_error( + "Triple hint does not match the actual endianness", HintEC)); + if (Stub.Target.BitWidth.getValue() != HintTarget.BitWidth.getValue()) + fatalError(make_error( + "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; } diff --git a/llvm/unittests/InterfaceStub/ELFYAMLTest.cpp b/llvm/unittests/InterfaceStub/ELFYAMLTest.cpp --- a/llvm/unittests/InterfaceStub/ELFYAMLTest.cpp +++ b/llvm/unittests/InterfaceStub/ELFYAMLTest.cpp @@ -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; diff --git a/llvm/utils/gn/secondary/llvm/test/BUILD.gn b/llvm/utils/gn/secondary/llvm/test/BUILD.gn --- a/llvm/utils/gn/secondary/llvm/test/BUILD.gn +++ b/llvm/utils/gn/secondary/llvm/test/BUILD.gn @@ -246,7 +246,6 @@ "//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", diff --git a/llvm/utils/gn/secondary/llvm/tools/llvm-elfabi/BUILD.gn b/llvm/utils/gn/secondary/llvm/tools/llvm-elfabi/BUILD.gn deleted file mode 100644 --- a/llvm/utils/gn/secondary/llvm/tools/llvm-elfabi/BUILD.gn +++ /dev/null @@ -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", - ] -}