Page MenuHomePhabricator

D60189.diff
No OneTemporary

File Metadata

Created
Sun, Jun 16, 9:48 PM

D60189.diff

Index: llvm/trunk/test/tools/llvm-objcopy/ELF/rename-section-flag.test
===================================================================
--- llvm/trunk/test/tools/llvm-objcopy/ELF/rename-section-flag.test
+++ llvm/trunk/test/tools/llvm-objcopy/ELF/rename-section-flag.test
@@ -12,7 +12,7 @@
# RUN: llvm-readobj --sections %t.noload | FileCheck %s --check-prefixes=CHECK,PROGBITS,WRITE
# 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,NOBITS
+# RUN: llvm-readobj --sections %t.readonly | FileCheck %s --check-prefixes=CHECK,PROGBITS
# 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
@@ -30,13 +30,13 @@
# RUN: llvm-readobj --sections %t.contents | FileCheck %s --check-prefixes=CHECK,PROGBITS,WRITE
# RUN: llvm-objcopy --rename-section=.foo=.bar,merge \
# RUN: --rename-section=.baz=.blah,merge %t %t.merge
-# RUN: llvm-readobj --sections %t.merge | FileCheck %s --check-prefixes=CHECK,NOBITS,MERGE,WRITE
+# RUN: llvm-readobj --sections %t.merge | FileCheck %s --check-prefixes=CHECK,PROGBITS,MERGE,WRITE
# RUN: llvm-objcopy --rename-section=.foo=.bar,strings \
# RUN: --rename-section=.baz=.blah,strings %t %t.strings
-# RUN: llvm-readobj --sections %t.strings | FileCheck %s --check-prefixes=CHECK,NOBITS,STRINGS,WRITE
+# RUN: llvm-readobj --sections %t.strings | FileCheck %s --check-prefixes=CHECK,PROGBITS,STRINGS,WRITE
# RUN: llvm-objcopy --rename-section=.foo=.bar,share \
# RUN: --rename-section=.baz=.blah,share %t %t.share
-# RUN: llvm-readobj --sections %t.share | FileCheck %s --check-prefixes=CHECK,NOBITS,WRITE
+# RUN: llvm-readobj --sections %t.share | FileCheck %s --check-prefixes=CHECK,PROGBITS,WRITE
# Multiple flags:
# RUN: llvm-objcopy --rename-section=.foo=.bar,alloc,readonly,strings \
@@ -44,7 +44,7 @@
# RUN: llvm-readobj --sections %t.alloc_ro_strings | FileCheck %s --check-prefixes=CHECK,NOBITS,ALLOC,STRINGS
# RUN: llvm-objcopy --rename-section=.foo=.bar,alloc,code \
# RUN: --rename-section=.baz=.blah,alloc,code %t %t.alloc_code
-# RUN: llvm-readobj --sections %t.alloc_code | FileCheck %s --check-prefixes=CHECK,PROGBITS,ALLOC,EXEC,WRITE
+# RUN: llvm-readobj --sections %t.alloc_code | FileCheck %s --check-prefixes=CHECK,NOBITS,ALLOC,EXEC,WRITE
# Invalid flags:
# RUN: not llvm-objcopy --rename-section=.foo=.bar,xyzzy %t %t.xyzzy 2>&1 | FileCheck %s --check-prefix=BAD-FLAG
Index: llvm/trunk/test/tools/llvm-objcopy/ELF/set-section-flags.test
===================================================================
--- llvm/trunk/test/tools/llvm-objcopy/ELF/set-section-flags.test
+++ llvm/trunk/test/tools/llvm-objcopy/ELF/set-section-flags.test
@@ -12,7 +12,7 @@
# RUN: llvm-readobj --sections %t.noload | FileCheck %s --check-prefixes=CHECK,PROGBITS,WRITE
# 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,NOBITS
+# RUN: llvm-readobj --sections %t.readonly | FileCheck %s --check-prefixes=CHECK,PROGBITS
# 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
@@ -30,13 +30,13 @@
# RUN: llvm-readobj --sections %t.contents | FileCheck %s --check-prefixes=CHECK,PROGBITS,WRITE
# RUN: llvm-objcopy --set-section-flags=.foo=merge \
# RUN: --set-section-flags=.baz=merge --set-section-flags=.rela.baz=merge %t %t.merge
-# RUN: llvm-readobj --sections %t.merge | FileCheck %s --check-prefixes=CHECK,MERGE,NOBITS,WRITE
+# RUN: llvm-readobj --sections %t.merge | FileCheck %s --check-prefixes=CHECK,MERGE,PROGBITS,WRITE
# RUN: llvm-objcopy --set-section-flags=.foo=strings \
# RUN: --set-section-flags=.baz=strings --set-section-flags=.rela.baz=strings %t %t.strings
-# RUN: llvm-readobj --sections %t.strings | FileCheck %s --check-prefixes=CHECK,STRINGS,NOBITS,WRITE
+# RUN: llvm-readobj --sections %t.strings | FileCheck %s --check-prefixes=CHECK,STRINGS,PROGBITS,WRITE
# RUN: llvm-objcopy --set-section-flags=.foo=share \
# RUN: --set-section-flags=.baz=share --set-section-flags=.rela.baz=share %t %t.share
-# RUN: llvm-readobj --sections %t.share | FileCheck %s --check-prefixes=CHECK,NOBITS,WRITE
+# RUN: llvm-readobj --sections %t.share | FileCheck %s --check-prefixes=CHECK,PROGBITS,WRITE
# Multiple flags:
# RUN: llvm-objcopy --set-section-flags=.foo=alloc,readonly,strings \
@@ -46,7 +46,7 @@
# RUN: llvm-objcopy --set-section-flags=.foo=alloc,code \
# RUN: --set-section-flags=.baz=alloc,code \
# RUN: --set-section-flags=.rela.baz=alloc,code %t %t.alloc_code
-# RUN: llvm-readobj --sections %t.alloc_code | FileCheck %s --check-prefixes=CHECK,PROGBITS,ALLOC,EXEC,WRITE
+# RUN: llvm-readobj --sections %t.alloc_code | FileCheck %s --check-prefixes=CHECK,NOBITS,ALLOC,EXEC,WRITE
# Invalid flags:
# RUN: not llvm-objcopy --set-section-flags=.foo=xyzzy %t %t.xyzzy 2>&1 | FileCheck %s --check-prefix=BAD-FLAG
Index: llvm/trunk/tools/llvm-objcopy/ELF/ELFObjcopy.cpp
===================================================================
--- llvm/trunk/tools/llvm-objcopy/ELF/ELFObjcopy.cpp
+++ llvm/trunk/tools/llvm-objcopy/ELF/ELFObjcopy.cpp
@@ -99,13 +99,12 @@
static void setSectionFlagsAndType(SectionBase &Sec, SectionFlag Flags) {
Sec.Flags = getSectionFlagsPreserveMask(Sec.Flags, getNewShfFlags(Flags));
- // Certain flags also promote SHT_NOBITS to SHT_PROGBITS. Don't change other
- // section types (RELA, SYMTAB, etc.).
- const SectionFlag NoBitsToProgBitsMask =
- SectionFlag::SecContents | SectionFlag::SecLoad | SectionFlag::SecNoload |
- SectionFlag::SecCode | SectionFlag::SecData | SectionFlag::SecRom |
- SectionFlag::SecDebug;
- if (Sec.Type == SHT_NOBITS && (Flags & NoBitsToProgBitsMask))
+ // In GNU objcopy, certain flags promote SHT_NOBITS to SHT_PROGBITS. This rule
+ // may promote more non-ALLOC sections than GNU objcopy, but it is fine as
+ // non-ALLOC SHT_NOBITS sections do not make much sense.
+ if (Sec.Type == SHT_NOBITS &&
+ (!(Sec.Flags & ELF::SHF_ALLOC) ||
+ Flags & (SectionFlag::SecContents | SectionFlag::SecLoad)))
Sec.Type = SHT_PROGBITS;
}

Event Timeline