diff options
author | quic-akaryaki <123192073+quic-akaryaki@users.noreply.github.com> | 2023-12-14 16:28:34 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-14 16:28:34 -0600 |
commit | 4070dffd34e99915b005c655086d92e42c004d25 (patch) | |
tree | 9851ede40d28e661301cd543a0feb6a3d3ab5f9c /llvm/tools/llvm-objcopy/ObjcopyOptions.cpp | |
parent | 5b470522cdd6af3796c05ecd7d979a74f9cb43a8 (diff) | |
download | llvm-4070dffd34e99915b005c655086d92e42c004d25.zip llvm-4070dffd34e99915b005c655086d92e42c004d25.tar.gz llvm-4070dffd34e99915b005c655086d92e42c004d25.tar.bz2 |
[llvm-objcopy] Add --gap-fill and --pad-to options (#65815)
`--gap-fill <value>` fills the gaps between sections with a specified
8-bit value, instead of zero.
`--pad-to <address>` pads the output binary up to the specified load
address, using the 8-bit value from `--gap-fill` or zero.
These options are only supported for ELF input and binary output.
Diffstat (limited to 'llvm/tools/llvm-objcopy/ObjcopyOptions.cpp')
-rw-r--r-- | llvm/tools/llvm-objcopy/ObjcopyOptions.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp b/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp index efc09f3..f15307181 100644 --- a/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp +++ b/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp @@ -737,6 +737,35 @@ objcopy::parseObjcopyOptions(ArrayRef<const char *> RawArgsArr, if (auto Arg = InputArgs.getLastArg(OBJCOPY_extract_partition)) Config.ExtractPartition = Arg->getValue(); + if (const auto *A = InputArgs.getLastArg(OBJCOPY_gap_fill)) { + if (Config.OutputFormat != FileFormat::Binary) + return createStringError( + errc::invalid_argument, + "'--gap-fill' is only supported for binary output"); + ErrorOr<uint64_t> Val = getAsInteger<uint64_t>(A->getValue()); + if (!Val) + return createStringError(Val.getError(), "--gap-fill: bad number: %s", + A->getValue()); + uint8_t ByteVal = Val.get(); + if (ByteVal != Val.get()) + return createStringError(std::errc::value_too_large, + "gap-fill value %s is out of range (0 to 0xff)", + A->getValue()); + Config.GapFill = ByteVal; + } + + if (const auto *A = InputArgs.getLastArg(OBJCOPY_pad_to)) { + if (Config.OutputFormat != FileFormat::Binary) + return createStringError( + errc::invalid_argument, + "'--pad-to' is only supported for binary output"); + ErrorOr<uint64_t> Addr = getAsInteger<uint64_t>(A->getValue()); + if (!Addr) + return createStringError(Addr.getError(), "--pad-to: bad number: %s", + A->getValue()); + Config.PadTo = *Addr; + } + for (auto *Arg : InputArgs.filtered(OBJCOPY_redefine_symbol)) { if (!StringRef(Arg->getValue()).contains('=')) return createStringError(errc::invalid_argument, |