[PATCH] D90438: [llvm-objcopy] Make --set-section-flags work with --add-section
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 29 16:33:53 PDT 2020
MaskRay created this revision.
MaskRay added reviewers: grimar, jhenderson, tra.
Herald added subscribers: llvm-commits, abrachet, emaste.
Herald added a reviewer: espindola.
Herald added a reviewer: alexshap.
Herald added a reviewer: rupprecht.
Herald added a project: LLVM.
MaskRay requested review of this revision.
This matches behavior GNU objcopy and can simplify clang-offload-bundler
(which currently works around the issue by invoking llvm-objcopy twice).
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D90438
Files:
llvm/test/tools/llvm-objcopy/ELF/add-section-and-set-flags.test
llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp
Index: llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp
===================================================================
--- llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp
+++ llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp
@@ -719,16 +719,6 @@
}
}
- if (!Config.SetSectionFlags.empty()) {
- for (auto &Sec : Obj.sections()) {
- const auto Iter = Config.SetSectionFlags.find(Sec.Name);
- if (Iter != Config.SetSectionFlags.end()) {
- const SectionFlagsUpdate &SFU = Iter->second;
- setSectionFlagsAndType(Sec, SFU.NewFlags);
- }
- }
- }
-
if (Config.OnlyKeepDebug)
for (auto &Sec : Obj.sections())
if (Sec.Flags & SHF_ALLOC && Sec.Type != SHT_NOTE)
@@ -752,6 +742,17 @@
NewSection.Type = SHT_NOTE;
}
+ // --set-section-flags works with sections added by --add-section.
+ if (!Config.SetSectionFlags.empty()) {
+ for (auto &Sec : Obj.sections()) {
+ const auto Iter = Config.SetSectionFlags.find(Sec.Name);
+ if (Iter != Config.SetSectionFlags.end()) {
+ const SectionFlagsUpdate &SFU = Iter->second;
+ setSectionFlagsAndType(Sec, SFU.NewFlags);
+ }
+ }
+ }
+
if (!Config.AddGnuDebugLink.empty())
Obj.addSection<GnuDebugLinkSection>(Config.AddGnuDebugLink,
Config.GnuDebugLinkCRC32);
Index: llvm/test/tools/llvm-objcopy/ELF/add-section-and-set-flags.test
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-objcopy/ELF/add-section-and-set-flags.test
@@ -0,0 +1,20 @@
+## Check --set-section-flags works with sections added by --add-section.
+
+# RUN: yaml2obj %s -o %t
+# RUN: llvm-objcopy --add-section=foo=/dev/null --set-section-flags=foo=alloc,exclude %t %t.out
+# RUN: llvm-readobj -S %t.out | FileCheck %s
+
+# CHECK: Name: foo
+# CHECK-NEXT: Type: SHT_PROGBITS
+# CHECK-NEXT: Flags [
+# CHECK-NEXT: SHF_ALLOC
+# CHECK-NEXT: SHF_EXCLUDE
+# CHECK-NEXT: SHF_WRITE
+# CHECK-NEXT: ]
+
+!ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_EXEC
+ Machine: EM_X86_64
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D90438.301785.patch
Type: text/x-patch
Size: 2109 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201029/bdaa9bd7/attachment.bin>
More information about the llvm-commits
mailing list