aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-elfabi/llvm-elfabi.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/tools/llvm-elfabi/llvm-elfabi.cpp')
-rw-r--r--llvm/tools/llvm-elfabi/llvm-elfabi.cpp48
1 files changed, 35 insertions, 13 deletions
diff --git a/llvm/tools/llvm-elfabi/llvm-elfabi.cpp b/llvm/tools/llvm-elfabi/llvm-elfabi.cpp
index 4e34de84..6fff54f 100644
--- a/llvm/tools/llvm-elfabi/llvm-elfabi.cpp
+++ b/llvm/tools/llvm-elfabi/llvm-elfabi.cpp
@@ -46,6 +46,17 @@ cl::opt<std::string>
SOName("soname",
cl::desc("Manually set the DT_SONAME entry of any emitted files"),
cl::value_desc("name"));
+cl::opt<ELFTarget> BinaryOutputTarget(
+ "output-target", cl::desc("Create a binary stub for the specified target"),
+ cl::values(clEnumValN(ELFTarget::ELF32LE, "elf32-little",
+ "32-bit little-endian ELF stub"),
+ clEnumValN(ELFTarget::ELF32BE, "elf32-big",
+ "32-bit big-endian ELF stub"),
+ clEnumValN(ELFTarget::ELF64LE, "elf64-little",
+ "64-bit little-endian ELF stub"),
+ clEnumValN(ELFTarget::ELF64BE, "elf64-big",
+ "64-bit big-endian ELF stub")));
+cl::opt<std::string> BinaryOutputFilePath(cl::Positional, cl::desc("output"));
/// writeTBE() writes a Text-Based ELF stub to a file using the latest version
/// of the YAML parser.
@@ -111,29 +122,40 @@ static Expected<std::unique_ptr<ELFStub>> readInputFile(StringRef FilePath) {
return EC.makeError();
}
+static void fatalError(Error Err) {
+ WithColor::defaultErrorHandler(std::move(Err));
+ exit(1);
+}
+
int main(int argc, char *argv[]) {
// Parse arguments.
cl::ParseCommandLineOptions(argc, argv);
Expected<std::unique_ptr<ELFStub>> StubOrErr = readInputFile(InputFilePath);
- if (!StubOrErr) {
- Error ReadError = StubOrErr.takeError();
- WithColor::error() << ReadError << "\n";
- exit(1);
- }
+ if (!StubOrErr)
+ fatalError(StubOrErr.takeError());
std::unique_ptr<ELFStub> TargetStub = std::move(StubOrErr.get());
- // Write out .tbe file.
+ // Change SoName before emitting stubs.
+ if (SOName.getNumOccurrences() == 1)
+ TargetStub->SoName = SOName;
+
if (EmitTBE.getNumOccurrences() == 1) {
TargetStub->TbeVersion = TBEVersionCurrent;
- if (SOName.getNumOccurrences() == 1) {
- TargetStub->SoName = SOName;
- }
Error TBEWriteError = writeTBE(EmitTBE, *TargetStub);
- if (TBEWriteError) {
- WithColor::error() << TBEWriteError << "\n";
- exit(1);
- }
+ if (TBEWriteError)
+ fatalError(std::move(TBEWriteError));
+ }
+
+ // Write out binary ELF stub.
+ if (BinaryOutputFilePath.getNumOccurrences() == 1) {
+ if (BinaryOutputTarget.getNumOccurrences() == 0)
+ fatalError(createStringError(errc::not_supported,
+ "no binary output target specified."));
+ Error BinaryWriteError =
+ writeBinaryStub(BinaryOutputFilePath, *TargetStub, BinaryOutputTarget);
+ if (BinaryWriteError)
+ fatalError(std::move(BinaryWriteError));
}
}