[llvm] e446322 - [llvm-objcopy][ELF] Allow setting SHF_EXCLUDE flag for ELF sections
Sergey Dmitriev via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 20 19:28:10 PST 2020
Author: Sergey Dmitriev
Date: 2020-01-20T18:56:45-08:00
New Revision: e446322f73fe6a6cb54057b5100880d5bc23bf2e
URL: https://github.com/llvm/llvm-project/commit/e446322f73fe6a6cb54057b5100880d5bc23bf2e
DIFF: https://github.com/llvm/llvm-project/commit/e446322f73fe6a6cb54057b5100880d5bc23bf2e.diff
LOG: [llvm-objcopy][ELF] Allow setting SHF_EXCLUDE flag for ELF sections
Summary: This patch adds support for setting SHF_EXCLUDE flag for ELF sections.
Reviewers: jhenderson, grimar, MaskRay, mstorsjo, espindola, alexshap, rupprecht
Reviewed By: jhenderson, MaskRay
Subscribers: emaste, abrachet, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D72128
Added:
Modified:
llvm/docs/CommandGuide/llvm-objcopy.rst
llvm/test/tools/llvm-objcopy/ELF/rename-section-flag-osproc-mask.test
llvm/test/tools/llvm-objcopy/ELF/rename-section-flag-preserved.test
llvm/test/tools/llvm-objcopy/ELF/rename-section-flag.test
llvm/test/tools/llvm-objcopy/ELF/set-section-flags.test
llvm/tools/llvm-objcopy/CopyConfig.cpp
llvm/tools/llvm-objcopy/CopyConfig.h
llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp
Removed:
################################################################################
diff --git a/llvm/docs/CommandGuide/llvm-objcopy.rst b/llvm/docs/CommandGuide/llvm-objcopy.rst
index 9237d739ad5d..525dcbfb0ea4 100644
--- a/llvm/docs/CommandGuide/llvm-objcopy.rst
+++ b/llvm/docs/CommandGuide/llvm-objcopy.rst
@@ -418,6 +418,7 @@ them.
- `load` = if the section has `SHT_NOBITS` type, mark it as a `SHT_PROGBITS`
section.
- `readonly` = if this flag is not specified, add the `SHF_WRITE` flag.
+ - `exclude` = add the `SHF_EXCLUDE` flag.
- `code` = add the `SHF_EXECINSTR` flag.
- `merge` = add the `SHF_MERGE` flag.
- `strings` = add the `SHF_STRINGS` flag.
diff --git a/llvm/test/tools/llvm-objcopy/ELF/rename-section-flag-osproc-mask.test b/llvm/test/tools/llvm-objcopy/ELF/rename-section-flag-osproc-mask.test
index 0d3224a41d31..ae572a6023f7 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/rename-section-flag-osproc-mask.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/rename-section-flag-osproc-mask.test
@@ -76,7 +76,6 @@ Sections:
# MIPS-NEXT: Type: SHT_PROGBITS
# MIPS-NEXT: Flags [
# MIPS-NEXT: SHF_ALLOC (0x2)
-# MIPS-NEXT: SHF_EXCLUDE (0x80000000)
# MIPS-NEXT: SHF_MIPS_ADDR (0x40000000)
# MIPS-NEXT: SHF_MIPS_GPREL (0x10000000)
# MIPS-NEXT: SHF_MIPS_LOCAL (0x4000000)
@@ -84,7 +83,6 @@ Sections:
# MIPS-NEXT: SHF_MIPS_NAMES (0x2000000)
# MIPS-NEXT: SHF_MIPS_NODUPES (0x1000000)
# MIPS-NEXT: SHF_MIPS_NOSTRIP (0x8000000)
-# MIPS-NEXT: SHF_MIPS_STRING (0x80000000)
# MIPS-NEXT: SHF_WRITE (0x1)
# MIPS-NEXT: ]
diff --git a/llvm/test/tools/llvm-objcopy/ELF/rename-section-flag-preserved.test b/llvm/test/tools/llvm-objcopy/ELF/rename-section-flag-preserved.test
index 2df9e3a039e0..e22920fe4e27 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/rename-section-flag-preserved.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/rename-section-flag-preserved.test
@@ -25,6 +25,8 @@
# RUN: llvm-readobj --sections %t.strings | FileCheck %s --check-prefixes=CHECK,STRINGS,WRITE
# RUN: llvm-objcopy --rename-section=.foo=.bar,share %t %t.share
# RUN: llvm-readobj --sections %t.share | FileCheck %s --check-prefixes=CHECK,WRITE
+# RUN: llvm-objcopy --rename-section=.foo=.bar,exclude %t %t.exclude
+# RUN: llvm-readobj --sections %t.exclude | FileCheck %s --check-prefixes=CHECK,WRITE,EXCLUDE
!ELF
FileHeader:
@@ -59,7 +61,7 @@ Symbols:
# CHECK-NEXT: Flags [
# ALLOC-NEXT: SHF_ALLOC (0x2)
# CHECK-NEXT: SHF_COMPRESSED (0x800)
-# CHECK-NEXT: SHF_EXCLUDE (0x80000000)
+# EXCLUDE-NEXT: SHF_EXCLUDE (0x80000000)
# EXEC-NEXT: SHF_EXECINSTR (0x4)
# CHECK-NEXT: SHF_GROUP (0x200)
# CHECK-NEXT: SHF_INFO_LINK (0x40)
@@ -69,5 +71,3 @@ Symbols:
# CHECK-NEXT: SHF_TLS (0x400)
# WRITE-NEXT: SHF_WRITE (0x1)
# CHECK-NEXT: ]
-
-# BAD-FLAG: unrecognized section flag 'xyzzy'
diff --git a/llvm/test/tools/llvm-objcopy/ELF/rename-section-flag.test b/llvm/test/tools/llvm-objcopy/ELF/rename-section-flag.test
index 0dbdbcc36b73..2638a7c1fdf4 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/rename-section-flag.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/rename-section-flag.test
@@ -13,6 +13,9 @@
# RUN: llvm-objcopy --rename-section=.foo=.bar,readonly \
# RUN: --rename-section=.baz=.blah,readonly %t %t.readonly
# RUN: llvm-readobj --sections %t.readonly | FileCheck %s --check-prefixes=CHECK,PROGBITS
+# RUN: llvm-objcopy --rename-section=.foo=.bar,exclude \
+# RUN: --rename-section=.baz=.blah,exclude %t %t.exclude
+# RUN: llvm-readobj --sections %t.exclude | FileCheck %s --check-prefixes=CHECK,PROGBITS,EXCLUDE,WRITE
# RUN: llvm-objcopy --rename-section=.foo=.bar,debug \
# RUN: --rename-section=.baz=.blah,debug %t %t.debug
# RUN: llvm-readobj --sections %t.debug | FileCheck %s --check-prefixes=CHECK,PROGBITS,WRITE
@@ -81,6 +84,7 @@ Sections:
# EXEC-NEXT: SHF_EXECINSTR (0x4)
# MERGE-NEXT: SHF_MERGE (0x10)
# STRINGS-NEXT: SHF_STRINGS (0x20)
+# EXCLUDE-NEXT: SHF_EXCLUDE (0x80000000)
# WRITE-NEXT: SHF_WRITE (0x1)
# CHECK-NEXT: ]
@@ -92,7 +96,8 @@ Sections:
# EXEC-NEXT: SHF_EXECINSTR (0x4)
# MERGE-NEXT: SHF_MERGE (0x10)
# STRINGS-NEXT: SHF_STRINGS (0x20)
+# EXCLUDE-NEXT: SHF_EXCLUDE (0x80000000)
# WRITE-NEXT: SHF_WRITE (0x1)
# CHECK-NEXT: ]
-# BAD-FLAG: unrecognized section flag 'xyzzy'. Flags supported for GNU compatibility: alloc, load, noload, readonly, debug, code, data, rom, share, contents, merge, strings
+# BAD-FLAG: unrecognized section flag 'xyzzy'. Flags supported for GNU compatibility: alloc, load, noload, readonly, exclude, debug, code, data, rom, share, contents, merge, strings
diff --git a/llvm/test/tools/llvm-objcopy/ELF/set-section-flags.test b/llvm/test/tools/llvm-objcopy/ELF/set-section-flags.test
index b1f3db465da8..54e3736e49be 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/set-section-flags.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/set-section-flags.test
@@ -13,6 +13,9 @@
# RUN: llvm-objcopy --set-section-flags=.foo=readonly \
# RUN: --set-section-flags=.baz=readonly --set-section-flags=.rela.baz=readonly %t %t.readonly
# RUN: llvm-readobj --sections %t.readonly | FileCheck %s --check-prefixes=CHECK,PROGBITS
+# RUN: llvm-objcopy --set-section-flags=.foo=exclude \
+# RUN: --set-section-flags=.baz=exclude --set-section-flags=.rela.baz=exclude %t %t.exclude
+# RUN: llvm-readobj --sections %t.exclude | FileCheck %s --check-prefixes=CHECK,PROGBITS,EXCLUDE,WRITE
# RUN: llvm-objcopy --set-section-flags=.foo=debug \
# RUN: --set-section-flags=.baz=debug --set-section-flags=.rela.baz=debug %t %t.debug
# RUN: llvm-readobj --sections %t.debug | FileCheck %s --check-prefixes=CHECK,PROGBITS,WRITE
@@ -93,6 +96,7 @@ Sections:
# EXEC-NEXT: SHF_EXECINSTR (0x4)
# MERGE-NEXT: SHF_MERGE (0x10)
# STRINGS-NEXT: SHF_STRINGS (0x20)
+# EXCLUDE-NEXT: SHF_EXCLUDE (0x80000000)
# WRITE-NEXT: SHF_WRITE (0x1)
# CHECK-NEXT: ]
@@ -104,6 +108,7 @@ Sections:
# EXEC-NEXT: SHF_EXECINSTR (0x4)
# MERGE-NEXT: SHF_MERGE (0x10)
# STRINGS-NEXT: SHF_STRINGS (0x20)
+# EXCLUDE-NEXT: SHF_EXCLUDE (0x80000000)
# WRITE-NEXT: SHF_WRITE (0x1)
# CHECK-NEXT: ]
@@ -114,10 +119,11 @@ Sections:
# EXEC-NEXT: SHF_EXECINSTR (0x4)
# MERGE-NEXT: SHF_MERGE (0x10)
# STRINGS-NEXT: SHF_STRINGS (0x20)
+# EXCLUDE-NEXT: SHF_EXCLUDE (0x80000000)
# WRITE-NEXT: SHF_WRITE (0x1)
# CHECK-NEXT: ]
# BAD-FORMAT: bad format for --set-section-flags: missing '='
# MULTIPLE-SETS: --set-section-flags set multiple times for section '.foo'
-# BAD-FLAG: unrecognized section flag 'xyzzy'. Flags supported for GNU compatibility: alloc, load, noload, readonly, debug, code, data, rom, share, contents, merge, strings
+# BAD-FLAG: unrecognized section flag 'xyzzy'. Flags supported for GNU compatibility: alloc, load, noload, readonly, exclude, debug, code, data, rom, share, contents, merge, strings
diff --git a/llvm/tools/llvm-objcopy/CopyConfig.cpp b/llvm/tools/llvm-objcopy/CopyConfig.cpp
index 73ed00b5cb2a..69d6180d86e0 100644
--- a/llvm/tools/llvm-objcopy/CopyConfig.cpp
+++ b/llvm/tools/llvm-objcopy/CopyConfig.cpp
@@ -146,6 +146,7 @@ static SectionFlag parseSectionRenameFlag(StringRef SectionName) {
.CaseLower("strings", SectionFlag::SecStrings)
.CaseLower("contents", SectionFlag::SecContents)
.CaseLower("share", SectionFlag::SecShare)
+ .CaseLower("exclude", SectionFlag::SecExclude)
.Default(SectionFlag::SecNone);
}
@@ -158,8 +159,8 @@ parseSectionFlagSet(ArrayRef<StringRef> SectionFlags) {
return createStringError(
errc::invalid_argument,
"unrecognized section flag '%s'. Flags supported for GNU "
- "compatibility: alloc, load, noload, readonly, debug, code, data, "
- "rom, share, contents, merge, strings",
+ "compatibility: alloc, load, noload, readonly, exclude, debug, "
+ "code, data, rom, share, contents, merge, strings",
Flag.str().c_str());
ParsedFlags |= ParsedFlag;
}
diff --git a/llvm/tools/llvm-objcopy/CopyConfig.h b/llvm/tools/llvm-objcopy/CopyConfig.h
index c262934b4a41..be1dca46b968 100644
--- a/llvm/tools/llvm-objcopy/CopyConfig.h
+++ b/llvm/tools/llvm-objcopy/CopyConfig.h
@@ -69,7 +69,8 @@ enum SectionFlag {
SecStrings = 1 << 9,
SecContents = 1 << 10,
SecShare = 1 << 11,
- LLVM_MARK_AS_BITMASK_ENUM(/* LargestValue = */ SecShare)
+ SecExclude = 1 << 12,
+ LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/SecExclude)
};
struct SectionRename {
diff --git a/llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp b/llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp
index a0cfd9a5ff86..fcf210903f6a 100644
--- a/llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp
+++ b/llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp
@@ -83,6 +83,8 @@ uint64_t getNewShfFlags(SectionFlag AllFlags) {
NewFlags |= ELF::SHF_MERGE;
if (AllFlags & SectionFlag::SecStrings)
NewFlags |= ELF::SHF_STRINGS;
+ if (AllFlags & SectionFlag::SecExclude)
+ NewFlags |= ELF::SHF_EXCLUDE;
return NewFlags;
}
@@ -90,10 +92,11 @@ static uint64_t getSectionFlagsPreserveMask(uint64_t OldFlags,
uint64_t NewFlags) {
// Preserve some flags which should not be dropped when setting flags.
// Also, preserve anything OS/processor dependant.
- const uint64_t PreserveMask = ELF::SHF_COMPRESSED | ELF::SHF_EXCLUDE |
- ELF::SHF_GROUP | ELF::SHF_LINK_ORDER |
- ELF::SHF_MASKOS | ELF::SHF_MASKPROC |
- ELF::SHF_TLS | ELF::SHF_INFO_LINK;
+ const uint64_t PreserveMask =
+ (ELF::SHF_COMPRESSED | ELF::SHF_GROUP | ELF::SHF_LINK_ORDER |
+ ELF::SHF_MASKOS | ELF::SHF_MASKPROC | ELF::SHF_TLS |
+ ELF::SHF_INFO_LINK) &
+ ~ELF::SHF_EXCLUDE;
return (OldFlags & PreserveMask) | (NewFlags & ~PreserveMask);
}
More information about the llvm-commits
mailing list