[llvm] Add functionality to llvm-objcopy to remove prefixes (PR #79415)

James Henderson via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 29 01:23:23 PST 2024


================
@@ -329,6 +329,10 @@ static Error updateAndRemoveSymbols(const CommonConfig &Config,
     if (I != Config.SymbolsToRename.end())
       Sym.Name = std::string(I->getValue());
 
+    if (!Config.SymbolsPrefixRemove.empty() && Sym.Type != STT_SECTION)
----------------
jh7370 wrote:

@MaskRay, I think this ordering looks about as good as any other to me, with one possible exception, but wanted a second opinion: is this the right place in the ordering for the symbol prefix removing functionality?

I think it makes sense to do options that modify a named symbol before renaming it (this is consistent with the general symbol renaming option immediately above). I think there's an unfortunate potential for confusion when also renaming symbols, as the prefix removal happens after the renaming, but at the same time, I'm not sure if it would be any less confusing if we did it the other way around.

Case 1 (current behaviour with this patch, --rename-symbols (option name and syntax possibly paraphrased - I'm too lazy to look it up) first, then --remove-prefix-symbols). In this case if you did `--rename-symbols foobar=bazbar` and `--remove-prefix-symbols=baz`, you'd end up with a symbol called `bar`. If you actually wanted a final symbol called `baz` you'd need to do the rename to `bazbazbar`.

Case 2 (do the options in the other order): if you did `--rename-symbols foobar=bazbar` and `--remove-prefix-symbols=foo`, you'd end up with a symbol named `bar`, since the prefix would have been removed before the renaming.

In other words, both orderings have some issues.

https://github.com/llvm/llvm-project/pull/79415


More information about the llvm-commits mailing list