[llvm] [llvm-objcopy] Add --change-section-address (PR #98664)
Eleanor Bonnici via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 24 06:53:00 PDT 2024
================
@@ -584,6 +584,65 @@ 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;
+ std::pair<StringRef, StringRef> UpdateParts;
+ std::string UpdateSymbol;
+
+ if (ArgValue.contains("+")) {
+ UpdateParts = ArgValue.split("+");
+ UpdateSymbol = '+';
+ } else if (ArgValue.contains("-")) {
+ UpdateParts = ArgValue.split("-");
+ UpdateSymbol = '-';
+ PatternUpdate.Update.Negative = true;
+ } else if (ArgValue.contains("=")) {
+ UpdateParts = ArgValue.split("=");
+ UpdateSymbol = '=';
+ PatternUpdate.Update.Absolute = true;
+ } else {
+ return createStringError(errc::invalid_argument,
+ "bad format for " + OptionName +
+ ": argument value " + ArgValue +
+ " is invalid. See help");
+ }
+
+ if (UpdateParts.second.empty()) {
+ if (UpdateSymbol == "+" || UpdateSymbol == "-")
+ return createStringError(errc::invalid_argument,
+ "bad format for " + OptionName +
+ ": missing value of offset after '" +
+ UpdateSymbol + "'");
+ else if (UpdateSymbol == "=")
+ return createStringError(errc::invalid_argument,
+ "bad format for " + OptionName +
+ ": missing address value after '='");
+ }
+ if (UpdateParts.first.empty())
+ return createStringError(
+ errc::invalid_argument,
+ "bad format for " + OptionName +
+ ": missing section pattern to apply address change to");
+
+ if (Error E = PatternUpdate.SectionPattern.addMatcher(NameOrPattern::create(
+ UpdateParts.first, SectionMatchStyle, ErrorCallback)))
+ return std::move(E);
----------------
eleanor-arm wrote:
It prints the problematic pattern so that looks enough for me. I've added a test for it.
https://github.com/llvm/llvm-project/pull/98664
More information about the llvm-commits
mailing list