[llvm] [llvm-objcopy] Add --change-section-address (PR #98664)
Eleanor Bonnici via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 26 09:17:37 PDT 2024
================
@@ -584,6 +584,69 @@ static Expected<int64_t> parseChangeSectionLMA(StringRef ArgValue,
return *LMAValue;
}
+static Expected<SectionPatternAddressUpdate>
+parseChangeSectionAddr(StringRef ArgValue, StringRef OptionName,
+ MatchStyle SectionMatchStyle,
+ function_ref<Error(Error)> ErrorCallback) {
+
+ SectionPatternAddressUpdate PatternUpdate;
+
+ size_t last_i = ArgValue.find_last_of("+-=");
+ StringRef Value = ArgValue.slice(last_i + 1, StringRef::npos);
+ StringRef SectionPattern = ArgValue.slice(0, last_i);
+
+ if (last_i == StringRef::npos)
+ return createStringError(errc::invalid_argument,
+ "bad format for " + OptionName +
+ ": argument value " + ArgValue +
+ " is invalid. See --help");
+
+ char UpdateSymbol = ArgValue[last_i];
+
+ switch (UpdateSymbol) {
+ case '+':
+ PatternUpdate.Update.Kind = AdjustKind::Add;
+ break;
+ case '-':
+ PatternUpdate.Update.Kind = AdjustKind::Subtract;
+ break;
+ case '=':
+ PatternUpdate.Update.Kind = AdjustKind::Set;
+ }
+
+ if (Value.empty()) {
+ if (UpdateSymbol == '+' || UpdateSymbol == '-')
----------------
eleanor-arm wrote:
The wording is slightly different depending on whether the action was setting the address or adjusting it.
https://github.com/llvm/llvm-project/pull/98664
More information about the llvm-commits
mailing list