[llvm] [llvm-objcopy][COFF] Support --rename-section (PR #210573)

Evgenii Kudriashov via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 2 11:56:04 PDT 2026


================
@@ -309,6 +309,29 @@ static Error handleArgs(const CommonConfig &Config,
     if (Error E = addGnuDebugLink(Obj, Config.AddGnuDebugLink))
       return E;
 
+  if (!Config.SectionsToRename.empty()) {
+    for (Section &Sec : Obj.getMutableSections()) {
+      auto It = Config.SectionsToRename.find(Sec.Name);
+      if (It == Config.SectionsToRename.end())
+        continue;
+
+      const SectionRename &SR = It->second;
+      StringRef OldName = Sec.Name;
+      StringRef NewName = SR.NewName;
+
+      // Update section-definition symbols that still share the section's name.
+      for (Symbol &Sym : Obj.getMutableSymbols()) {
+        if (Sym.Name == OldName && Sym.TargetSectionId == Sec.UniqueId)
----------------
e-kud wrote:

I believe a check of `StorageClass == IMAGE_SYM_CLASS_STATIC` is required, could an external symbol share the name with a section? 

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


More information about the llvm-commits mailing list