[llvm] Add adjustVMA option (PR #72870)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 20 05:54:13 PST 2023
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff 4d64a2bcd31818aa0aed0ce9e6b64898a6f0eb55 7927856329b51c3a173bb87ae0a5e1f047467e2c -- llvm/include/llvm/ObjCopy/CommonConfig.h llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp b/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp
index 245c11457d..ac84ec21a3 100644
--- a/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp
+++ b/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp
@@ -655,11 +655,10 @@ static Error handleArgs(const CommonConfig &Config, const ELFConfig &ELFConfig,
if (Config.SectionVMA != 0) {
for (SectionBase &Sec : Obj.sections()) {
bool AdjustThisSection = false;
- if (Config.SectionName.empty() ||
- Config.SectionName.contains(Sec.Name)){
+ if (Config.SectionName.empty() || Config.SectionName.contains(Sec.Name)) {
AdjustThisSection = true;
}
- if ((Sec.Flags & ELF::SHF_ALLOC) && AdjustThisSection){
+ if ((Sec.Flags & ELF::SHF_ALLOC) && AdjustThisSection) {
if (Config.SectionSet)
Sec.Addr = 0;
Sec.Addr += Config.SectionVMA;
diff --git a/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp b/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
index e2973c9171..23d3e28ce6 100644
--- a/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
+++ b/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
@@ -536,42 +536,39 @@ static Error loadNewSectionData(StringRef ArgValue, StringRef OptionName,
// readChangeSectionVMA reads the command line arguments and sets
// sectionName and adjustValue of VMA and LMA addresses.
static Error readChangeSectionVMA(StringRef ArgValue, StringRef OptionName,
- StringRef& SectionName, int64_t& AdjustValue, bool& setValue) {
+ StringRef &SectionName, int64_t &AdjustValue,
+ bool &setValue) {
SectionName = "";
AdjustValue = 0;
std::pair<StringRef, StringRef> SecPair;
- if (ArgValue.contains("=")){
+ if (ArgValue.contains("=")) {
setValue = true;
SecPair = ArgValue.split("=");
- }
- else if (ArgValue.contains("+")){
+ } else if (ArgValue.contains("+")) {
setValue = false;
SecPair = ArgValue.split("+");
- }
- else if (ArgValue.contains("-")){
+ } else if (ArgValue.contains("-")) {
setValue = false;
SecPair = ArgValue.split("-");
- }
- else{
+ } else {
return createStringError(errc::invalid_argument,
- "bad format for " + OptionName + ": missing '='");
+ "bad format for " + OptionName + ": missing '='");
}
if (SecPair.second.empty())
- return createStringError(errc::invalid_argument, "bad format for " +
- OptionName +
- ": missing offset of VMA");
+ return createStringError(errc::invalid_argument,
+ "bad format for " + OptionName +
+ ": missing offset of VMA");
SectionName = SecPair.first;
auto ChangeValue = getAsInteger<int64_t>(SecPair.second);
if (!ChangeValue)
return createStringError(ChangeValue.getError(),
- "Unable to parse adjustment value");
+ "Unable to parse adjustment value");
AdjustValue = *ChangeValue;
if (ArgValue.contains("-"))
AdjustValue *= -1;
return Error::success();
}
-
// parseObjcopyOptions returns the config and sets the input arguments. If a
// help flag is set then parseObjcopyOptions will print the help messege and
// exit.
@@ -868,8 +865,9 @@ objcopy::parseObjcopyOptions(ArrayRef<const char *> RawArgsArr,
return std::move(Err);
}
for (auto *Arg : InputArgs.filtered(OBJCOPY_adjust_section_vma)) {
- if (Error Err = readChangeSectionVMA(Arg->getValue(), "--adjust-section-vma",
- Config.SectionName, Config.SectionVMA, Config.SectionSet))
+ if (Error Err = readChangeSectionVMA(
+ Arg->getValue(), "--adjust-section-vma", Config.SectionName,
+ Config.SectionVMA, Config.SectionSet))
return std::move(Err);
}
for (auto *Arg : InputArgs.filtered(OBJCOPY_dump_section)) {
@@ -1011,7 +1009,7 @@ objcopy::parseObjcopyOptions(ArrayRef<const char *> RawArgsArr,
ELFConfig.EntryExpr = [Expr, EIncr](uint64_t EAddr) {
return Expr(EAddr) + *EIncr;
};
- } else if(Arg->getOption().matches(OBJCOPY_adjust_vma)){
+ } else if (Arg->getOption().matches(OBJCOPY_adjust_vma)) {
auto EIncr = getAsInteger<int64_t>(Arg->getValue());
if (!EIncr)
return createStringError(EIncr.getError(),
``````````
</details>
https://github.com/llvm/llvm-project/pull/72870
More information about the llvm-commits
mailing list