[PATCH] D60200: [llvm-objcopy] Make section rename/set flags case-insensitive
James Henderson via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 3 07:12:45 PDT 2019
jhenderson created this revision.
jhenderson added reviewers: grimar, rupprecht, jakehehrlich.
Herald added subscribers: MaskRay, arichardson, emaste.
Herald added a reviewer: espindola.
Herald added a reviewer: alexshap.
Herald added a project: LLVM.
This fixes https://bugs.llvm.org/show_bug.cgi?id=41305. GNU objcopy --set-section-flags/--rename-section flags are case-insensitive, so this patch updates llvm-objcopy to match.
Repository:
rL LLVM
https://reviews.llvm.org/D60200
Files:
test/tools/llvm-objcopy/ELF/rename-section-flag.test
test/tools/llvm-objcopy/ELF/set-section-flags.test
tools/llvm-objcopy/CopyConfig.cpp
Index: tools/llvm-objcopy/CopyConfig.cpp
===================================================================
--- tools/llvm-objcopy/CopyConfig.cpp
+++ tools/llvm-objcopy/CopyConfig.cpp
@@ -94,18 +94,18 @@
static SectionFlag parseSectionRenameFlag(StringRef SectionName) {
return llvm::StringSwitch<SectionFlag>(SectionName)
- .Case("alloc", SectionFlag::SecAlloc)
- .Case("load", SectionFlag::SecLoad)
- .Case("noload", SectionFlag::SecNoload)
- .Case("readonly", SectionFlag::SecReadonly)
- .Case("debug", SectionFlag::SecDebug)
- .Case("code", SectionFlag::SecCode)
- .Case("data", SectionFlag::SecData)
- .Case("rom", SectionFlag::SecRom)
- .Case("merge", SectionFlag::SecMerge)
- .Case("strings", SectionFlag::SecStrings)
- .Case("contents", SectionFlag::SecContents)
- .Case("share", SectionFlag::SecShare)
+ .CaseLower("alloc", SectionFlag::SecAlloc)
+ .CaseLower("load", SectionFlag::SecLoad)
+ .CaseLower("noload", SectionFlag::SecNoload)
+ .CaseLower("readonly", SectionFlag::SecReadonly)
+ .CaseLower("debug", SectionFlag::SecDebug)
+ .CaseLower("code", SectionFlag::SecCode)
+ .CaseLower("data", SectionFlag::SecData)
+ .CaseLower("rom", SectionFlag::SecRom)
+ .CaseLower("merge", SectionFlag::SecMerge)
+ .CaseLower("strings", SectionFlag::SecStrings)
+ .CaseLower("contents", SectionFlag::SecContents)
+ .CaseLower("share", SectionFlag::SecShare)
.Default(SectionFlag::SecNone);
}
Index: test/tools/llvm-objcopy/ELF/set-section-flags.test
===================================================================
--- test/tools/llvm-objcopy/ELF/set-section-flags.test
+++ test/tools/llvm-objcopy/ELF/set-section-flags.test
@@ -57,6 +57,16 @@
# Setting flags for the same section multiple times:
# RUN: not llvm-objcopy --set-section-flags=.foo=alloc --set-section-flags=.foo=load %t %t2 2>&1 | FileCheck %s --check-prefix=MULTIPLE-SETS
+# Upper and mixed-case flags:
+# RUN: llvm-objcopy --set-section-flags=.foo=ALLOC,LOAD,NOLOAD,READONLY,DEBUG,CODE,DATA,ROM,CONTENTS,MERGE,STRINGS,SHARE \
+# RUN: --set-section-flags=.baz=ALLOC,LOAD,NOLOAD,READONLY,DEBUG,CODE,DATA,ROM,CONTENTS,MERGE,STRINGS,SHARE \
+# RUN: --set-section-flags=.rela.baz=ALLOC,LOAD,NOLOAD,READONLY,DEBUG,CODE,DATA,ROM,CONTENTS,MERGE,STRINGS,SHARE %t %t.upper
+# RUN: llvm-readobj --sections %t.upper | FileCheck %s --check-prefixes=CHECK,PROGBITS,ALLOC,EXEC,MERGE,STRINGS
+# RUN: llvm-objcopy --set-section-flags=.foo=aLlOc,LoAd,NoLoad,rEAdONly,Debug,codE,DaTa,rOm,CoNtEnTs,mErGe,sTRINGs,SharE \
+# RUN: --set-section-flags=.baz=aLlOc,LoAd,NoLoad,rEAdONly,Debug,codE,DaTa,rOm,CoNtEnTs,mErGe,sTRINGs,SharE \
+# RUN: --set-section-flags=.rela.baz=aLlOc,LoAd,NoLoad,rEAdONly,Debug,codE,DaTa,rOm,CoNtEnTs,mErGe,sTRINGs,SharE %t %t.mixed
+# RUN: llvm-readobj --sections %t.mixed | FileCheck %s --check-prefixes=CHECK,PROGBITS,ALLOC,EXEC,MERGE,STRINGS
+
!ELF
FileHeader:
Class: ELFCLASS64
Index: test/tools/llvm-objcopy/ELF/rename-section-flag.test
===================================================================
--- test/tools/llvm-objcopy/ELF/rename-section-flag.test
+++ test/tools/llvm-objcopy/ELF/rename-section-flag.test
@@ -49,6 +49,14 @@
# Invalid flags:
# RUN: not llvm-objcopy --rename-section=.foo=.bar,xyzzy %t %t.xyzzy 2>&1 | FileCheck %s --check-prefix=BAD-FLAG
+# Upper-case flags:
+# RUN: llvm-objcopy --rename-section=.foo=.bar,ALLOC,LOAD,NOLOAD,READONLY,DEBUG,CODE,DATA,ROM,CONTENTS,MERGE,STRINGS,SHARE \
+# RUN: --rename-section=.baz=.blah,ALLOC,LOAD,NOLOAD,READONLY,DEBUG,CODE,DATA,ROM,CONTENTS,MERGE,STRINGS,SHARE %t %t.upper
+# RUN: llvm-readobj --sections %t.upper | FileCheck %s --check-prefixes=CHECK,PROGBITS,ALLOC,EXEC,MERGE,STRINGS
+# RUN: llvm-objcopy --rename-section=.foo=.bar,aLlOc,LoAd,NoLoad,rEAdONly,Debug,codE,DaTa,rOm,CoNtEnTs,mErGe,sTRINGs,SharE \
+# RUN: --rename-section=.baz=.blah,aLlOc,LoAd,NoLoad,rEAdONly,Debug,codE,DaTa,rOm,CoNtEnTs,mErGe,sTRINGs,SharE %t %t.mixed
+# RUN: llvm-readobj --sections %t.mixed | FileCheck %s --check-prefixes=CHECK,PROGBITS,ALLOC,EXEC,MERGE,STRINGS
+
!ELF
FileHeader:
Class: ELFCLASS64
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D60200.193487.patch
Type: text/x-patch
Size: 4220 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190403/d60eab70/attachment-0001.bin>
More information about the llvm-commits
mailing list