[llvm] r357492 - [llvm-objcopy] Change SHT_NOBITS to SHT_PROBITS for some --set-section-flags

Jordan Rupprecht via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 2 09:49:56 PDT 2019


Author: rupprecht
Date: Tue Apr  2 09:49:56 2019
New Revision: 357492

URL: http://llvm.org/viewvc/llvm-project?rev=357492&view=rev
Log:
[llvm-objcopy] Change SHT_NOBITS to SHT_PROBITS for some --set-section-flags

Summary:
Some flags accepted by --set-section-flags and --rename-section can change a SHT_NOBITS section to a SHT_PROGBITS section. Note that none of them can change a SHT_PROGBITS to SHT_NOBITS.

The full list (found via experimentation of individually setting each flag) that does this is: contents, load, noload, code, data, rom, and debug.

This was found by testing llvm-objcopy with the gnu binutils test suite, specifically this test case: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=blob;f=binutils/testsuite/binutils-all/copy-1.d;h=f2b0d9e90df738c2891b4d5c7b62f62894b556ca;hb=HEAD

Reviewers: jhenderson, grimar, jakehehrlich, alexshap, espindola

Reviewed By: jhenderson

Subscribers: emaste, arichardson, MaskRay, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D59958

Modified:
    llvm/trunk/test/tools/llvm-objcopy/ELF/rename-section-flag.test
    llvm/trunk/test/tools/llvm-objcopy/ELF/set-section-flags.test
    llvm/trunk/tools/llvm-objcopy/ELF/ELFObjcopy.cpp

Modified: llvm/trunk/test/tools/llvm-objcopy/ELF/rename-section-flag.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objcopy/ELF/rename-section-flag.test?rev=357492&r1=357491&r2=357492&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-objcopy/ELF/rename-section-flag.test (original)
+++ llvm/trunk/test/tools/llvm-objcopy/ELF/rename-section-flag.test Tue Apr  2 09:49:56 2019
@@ -1,36 +1,50 @@
 # RUN: yaml2obj %s > %t
 
 # Single flags on a section with no flags:
-# RUN: llvm-objcopy --rename-section=.foo=.bar,alloc %t %t.alloc
-# RUN: llvm-readobj --sections %t.alloc | FileCheck %s --check-prefixes=CHECK,ALLOC,WRITE
-# RUN: llvm-objcopy --rename-section=.foo=.bar,load %t %t.load
-# RUN: llvm-readobj --sections %t.load | FileCheck %s --check-prefixes=CHECK,WRITE
-# RUN: llvm-objcopy --rename-section=.foo=.bar,noload %t %t.noload
-# RUN: llvm-readobj --sections %t.noload | FileCheck %s --check-prefixes=CHECK,WRITE
-# RUN: llvm-objcopy --rename-section=.foo=.bar,readonly %t %t.readonly
-# RUN: llvm-readobj --sections %t.readonly | FileCheck %s --check-prefixes=CHECK
-# RUN: llvm-objcopy --rename-section=.foo=.bar,debug %t %t.debug
-# RUN: llvm-readobj --sections %t.debug | FileCheck %s --check-prefixes=CHECK,WRITE
-# RUN: llvm-objcopy --rename-section=.foo=.bar,code %t %t.code
-# RUN: llvm-readobj --sections %t.code | FileCheck %s --check-prefixes=CHECK,EXEC,WRITE
-# RUN: llvm-objcopy --rename-section=.foo=.bar,data %t %t.data
-# RUN: llvm-readobj --sections %t.data | FileCheck %s --check-prefixes=CHECK,WRITE
-# RUN: llvm-objcopy --rename-section=.foo=.bar,rom %t %t.rom
-# RUN: llvm-readobj --sections %t.rom | FileCheck %s --check-prefixes=CHECK,WRITE
-# RUN: llvm-objcopy --rename-section=.foo=.bar,contents %t %t.contents
-# RUN: llvm-readobj --sections %t.contents | FileCheck %s --check-prefixes=CHECK,WRITE
-# RUN: llvm-objcopy --rename-section=.foo=.bar,merge %t %t.merge
-# RUN: llvm-readobj --sections %t.merge | FileCheck %s --check-prefixes=CHECK,MERGE,WRITE
-# RUN: llvm-objcopy --rename-section=.foo=.bar,strings %t %t.strings
-# 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,alloc  \
+# RUN:   --rename-section=.baz=.blah,alloc %t %t.alloc
+# RUN: llvm-readobj --sections %t.alloc | FileCheck %s --check-prefixes=CHECK,NOBITS,ALLOC,WRITE
+# RUN: llvm-objcopy --rename-section=.foo=.bar,load  \
+# RUN:   --rename-section=.baz=.blah,load %t %t.load
+# RUN: llvm-readobj --sections %t.load | FileCheck %s --check-prefixes=CHECK,PROGBITS,WRITE
+# RUN: llvm-objcopy --rename-section=.foo=.bar,noload  \
+# RUN:   --rename-section=.baz=.blah,noload %t %t.noload
+# 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-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
+# RUN: llvm-objcopy --rename-section=.foo=.bar,code  \
+# RUN:   --rename-section=.baz=.blah,code %t %t.code
+# RUN: llvm-readobj --sections %t.code | FileCheck %s --check-prefixes=CHECK,PROGBITS,EXEC,WRITE
+# RUN: llvm-objcopy --rename-section=.foo=.bar,data  \
+# RUN:   --rename-section=.baz=.blah,data %t %t.data
+# RUN: llvm-readobj --sections %t.data | FileCheck %s --check-prefixes=CHECK,PROGBITS,WRITE
+# RUN: llvm-objcopy --rename-section=.foo=.bar,rom  \
+# RUN:   --rename-section=.baz=.blah,rom %t %t.rom
+# RUN: llvm-readobj --sections %t.rom | FileCheck %s --check-prefixes=CHECK,PROGBITS,WRITE
+# RUN: llvm-objcopy --rename-section=.foo=.bar,contents  \
+# RUN:   --rename-section=.baz=.blah,contents %t %t.contents
+# 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-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-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
 
 # Multiple flags:
-# RUN: llvm-objcopy --rename-section=.foo=.bar,alloc,readonly,strings %t %t.alloc_ro_strings
-# RUN: llvm-readobj --sections %t.alloc_ro_strings | FileCheck %s --check-prefixes=CHECK,ALLOC,STRINGS
-# RUN: llvm-objcopy --rename-section=.foo=.bar,alloc,code %t %t.alloc_code
-# RUN: llvm-readobj --sections %t.alloc_code | FileCheck %s --check-prefixes=CHECK,ALLOC,EXEC,WRITE
+# RUN: llvm-objcopy --rename-section=.foo=.bar,alloc,readonly,strings  \
+# RUN:   --rename-section=.baz=.blah,alloc,readonly,strings %t %t.alloc_ro_strings
+# 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
 
 # Invalid flags:
 # RUN: not llvm-objcopy --rename-section=.foo=.bar,xyzzy %t %t.xyzzy 2>&1 | FileCheck %s --check-prefix=BAD-FLAG
@@ -45,16 +59,30 @@ Sections:
   - Name:            .foo
     Type:            SHT_PROGBITS
     Flags:           [ ]
-    Content:        "c3c3c3c3"
+    Content:         "c3c3c3c3"
+  - Name:            .baz
+    Type:            SHT_NOBITS
+    Flags:           [ ]
 
-# CHECK:        Name: .bar
-# CHECK-NEXT:   Type: SHT_PROGBITS
-# CHECK-NEXT:   Flags [
-# ALLOC-NEXT:     SHF_ALLOC (0x2)
-# EXEC-NEXT:      SHF_EXECINSTR (0x4)
-# MERGE-NEXT:     SHF_MERGE (0x10)
-# STRINGS-NEXT:   SHF_STRINGS (0x20)
-# WRITE-NEXT:     SHF_WRITE (0x1)
-# CHECK-NEXT:   ]
+# CHECK:         Name: .bar
+# CHECK-NEXT:    Type: SHT_PROGBITS
+# CHECK-NEXT:    Flags [
+# ALLOC-NEXT:      SHF_ALLOC (0x2)
+# EXEC-NEXT:       SHF_EXECINSTR (0x4)
+# MERGE-NEXT:      SHF_MERGE (0x10)
+# STRINGS-NEXT:    SHF_STRINGS (0x20)
+# WRITE-NEXT:      SHF_WRITE (0x1)
+# CHECK-NEXT:    ]
+
+# CHECK:         Name: .blah
+# NOBITS-NEXT:   Type: SHT_NOBITS
+# PROGBITS-NEXT: Type: SHT_PROGBITS
+# CHECK-NEXT:    Flags [
+# ALLOC-NEXT:      SHF_ALLOC (0x2)
+# EXEC-NEXT:       SHF_EXECINSTR (0x4)
+# MERGE-NEXT:      SHF_MERGE (0x10)
+# STRINGS-NEXT:    SHF_STRINGS (0x20)
+# 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

Modified: llvm/trunk/test/tools/llvm-objcopy/ELF/set-section-flags.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objcopy/ELF/set-section-flags.test?rev=357492&r1=357491&r2=357492&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-objcopy/ELF/set-section-flags.test (original)
+++ llvm/trunk/test/tools/llvm-objcopy/ELF/set-section-flags.test Tue Apr  2 09:49:56 2019
@@ -1,36 +1,52 @@
 # RUN: yaml2obj %s > %t
 
 # Single flags on a section with no flags:
-# RUN: llvm-objcopy --set-section-flags=.foo=alloc %t %t.alloc
-# RUN: llvm-readobj --sections %t.alloc | FileCheck %s --check-prefixes=CHECK,ALLOC,WRITE
-# RUN: llvm-objcopy --set-section-flags=.foo=load %t %t.load
-# RUN: llvm-readobj --sections %t.load | FileCheck %s --check-prefixes=CHECK,WRITE
-# RUN: llvm-objcopy --set-section-flags=.foo=noload %t %t.noload
-# RUN: llvm-readobj --sections %t.noload | FileCheck %s --check-prefixes=CHECK,WRITE
-# RUN: llvm-objcopy --set-section-flags=.foo=readonly %t %t.readonly
-# RUN: llvm-readobj --sections %t.readonly | FileCheck %s --check-prefixes=CHECK
-# RUN: llvm-objcopy --set-section-flags=.foo=debug %t %t.debug
-# RUN: llvm-readobj --sections %t.debug | FileCheck %s --check-prefixes=CHECK,WRITE
-# RUN: llvm-objcopy --set-section-flags=.foo=code %t %t.code
-# RUN: llvm-readobj --sections %t.code | FileCheck %s --check-prefixes=CHECK,EXEC,WRITE
-# RUN: llvm-objcopy --set-section-flags=.foo=data %t %t.data
-# RUN: llvm-readobj --sections %t.data | FileCheck %s --check-prefixes=CHECK,WRITE
-# RUN: llvm-objcopy --set-section-flags=.foo=rom %t %t.rom
-# RUN: llvm-readobj --sections %t.rom | FileCheck %s --check-prefixes=CHECK,WRITE
-# RUN: llvm-objcopy --set-section-flags=.foo=contents %t %t.contents
-# RUN: llvm-readobj --sections %t.contents | FileCheck %s --check-prefixes=CHECK,WRITE
-# RUN: llvm-objcopy --set-section-flags=.foo=merge %t %t.merge
-# RUN: llvm-readobj --sections %t.merge | FileCheck %s --check-prefixes=CHECK,MERGE,WRITE
-# RUN: llvm-objcopy --set-section-flags=.foo=strings %t %t.strings
-# RUN: llvm-readobj --sections %t.strings | FileCheck %s --check-prefixes=CHECK,STRINGS,WRITE
-# RUN: llvm-objcopy --set-section-flags=.foo=share %t %t.share
-# RUN: llvm-readobj --sections %t.share | FileCheck %s --check-prefixes=CHECK,WRITE
+# RUN: llvm-objcopy --set-section-flags=.foo=alloc \
+# RUN:   --set-section-flags=.baz=alloc --set-section-flags=.rela.baz=alloc %t %t.alloc
+# RUN: llvm-readobj --sections %t.alloc | FileCheck %s --check-prefixes=CHECK,NOBITS,ALLOC,WRITE
+# RUN: llvm-objcopy --set-section-flags=.foo=load \
+# RUN:   --set-section-flags=.baz=load --set-section-flags=.rela.baz=load %t %t.load
+# RUN: llvm-readobj --sections %t.load | FileCheck %s --check-prefixes=CHECK,PROGBITS,WRITE
+# RUN: llvm-objcopy --set-section-flags=.foo=noload \
+# RUN:   --set-section-flags=.baz=noload --set-section-flags=.rela.baz=noload %t %t.noload
+# 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-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
+# RUN: llvm-objcopy --set-section-flags=.foo=code \
+# RUN:   --set-section-flags=.baz=code --set-section-flags=.rela.baz=code %t %t.code
+# RUN: llvm-readobj --sections %t.code | FileCheck %s --check-prefixes=CHECK,PROGBITS,EXEC,WRITE
+# RUN: llvm-objcopy --set-section-flags=.foo=data \
+# RUN:   --set-section-flags=.baz=data --set-section-flags=.rela.baz=data %t %t.data
+# RUN: llvm-readobj --sections %t.data | FileCheck %s --check-prefixes=CHECK,PROGBITS,WRITE
+# RUN: llvm-objcopy --set-section-flags=.foo=rom \
+# RUN:   --set-section-flags=.baz=rom --set-section-flags=.rela.baz=rom %t %t.rom
+# RUN: llvm-readobj --sections %t.rom | FileCheck %s --check-prefixes=CHECK,PROGBITS,WRITE
+# RUN: llvm-objcopy --set-section-flags=.foo=contents \
+# RUN:   --set-section-flags=.baz=contents --set-section-flags=.rela.baz=contents %t %t.contents
+# 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-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-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
 
 # Multiple flags:
-# RUN: llvm-objcopy --set-section-flags=.foo=alloc,readonly,strings %t %t.alloc_ro_strings
-# RUN: llvm-readobj --sections %t.alloc_ro_strings | FileCheck %s --check-prefixes=CHECK,ALLOC,STRINGS
-# RUN: llvm-objcopy --set-section-flags=.foo=alloc,code %t %t.alloc_code
-# RUN: llvm-readobj --sections %t.alloc_code | FileCheck %s --check-prefixes=CHECK,ALLOC,EXEC,WRITE
+# RUN: llvm-objcopy --set-section-flags=.foo=alloc,readonly,strings \
+# RUN:   --set-section-flags=.baz=alloc,readonly,strings \
+# RUN:   --set-section-flags=.rela.baz=alloc,readonly,strings %t %t.alloc_ro_strings
+# RUN: llvm-readobj --sections %t.alloc_ro_strings | FileCheck %s --check-prefixes=CHECK,NOBITS,ALLOC,STRINGS
+# 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
 
 # Invalid flags:
 # RUN: not llvm-objcopy --set-section-flags=.foo=xyzzy %t %t.xyzzy 2>&1 | FileCheck %s --check-prefix=BAD-FLAG
@@ -51,16 +67,43 @@ Sections:
   - Name:            .foo
     Type:            SHT_PROGBITS
     Flags:           [ ]
-
-# CHECK:        Name: .foo
-# CHECK-NEXT:   Type: SHT_PROGBITS
-# CHECK-NEXT:   Flags [
-# ALLOC-NEXT:     SHF_ALLOC (0x2)
-# EXEC-NEXT:      SHF_EXECINSTR (0x4)
-# MERGE-NEXT:     SHF_MERGE (0x10)
-# STRINGS-NEXT:   SHF_STRINGS (0x20)
-# WRITE-NEXT:     SHF_WRITE (0x1)
-# CHECK-NEXT:   ]
+  - Name:            .baz
+    Type:            SHT_NOBITS
+    Flags:           [ ]
+  - Name:            .rela.baz
+    Type:            SHT_RELA
+    Info:            .baz
+
+# CHECK:         Name: .foo
+# CHECK-NEXT:    Type: SHT_PROGBITS
+# CHECK-NEXT:    Flags [
+# ALLOC-NEXT:      SHF_ALLOC (0x2)
+# EXEC-NEXT:       SHF_EXECINSTR (0x4)
+# MERGE-NEXT:      SHF_MERGE (0x10)
+# STRINGS-NEXT:    SHF_STRINGS (0x20)
+# WRITE-NEXT:      SHF_WRITE (0x1)
+# CHECK-NEXT:    ]
+
+# CHECK:         Name: .baz
+# NOBITS-NEXT:   Type: SHT_NOBITS
+# PROGBITS-NEXT: Type: SHT_PROGBITS
+# CHECK-NEXT:    Flags [
+# ALLOC-NEXT:      SHF_ALLOC (0x2)
+# EXEC-NEXT:       SHF_EXECINSTR (0x4)
+# MERGE-NEXT:      SHF_MERGE (0x10)
+# STRINGS-NEXT:    SHF_STRINGS (0x20)
+# WRITE-NEXT:      SHF_WRITE (0x1)
+# CHECK-NEXT:    ]
+
+# CHECK:         Name: .rela.baz
+# CHECK-NEXT:    Type: SHT_RELA
+# CHECK-NEXT:    Flags [
+# ALLOC-NEXT:      SHF_ALLOC (0x2)
+# EXEC-NEXT:       SHF_EXECINSTR (0x4)
+# MERGE-NEXT:      SHF_MERGE (0x10)
+# STRINGS-NEXT:    SHF_STRINGS (0x20)
+# 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

Modified: llvm/trunk/tools/llvm-objcopy/ELF/ELFObjcopy.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objcopy/ELF/ELFObjcopy.cpp?rev=357492&r1=357491&r2=357492&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objcopy/ELF/ELFObjcopy.cpp (original)
+++ llvm/trunk/tools/llvm-objcopy/ELF/ELFObjcopy.cpp Tue Apr  2 09:49:56 2019
@@ -85,7 +85,7 @@ uint64_t getNewShfFlags(SectionFlag AllF
   return NewFlags;
 }
 
-static uint64_t setSectionFlagsPreserveMask(uint64_t OldFlags,
+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.
@@ -96,6 +96,19 @@ static uint64_t setSectionFlagsPreserveM
   return (OldFlags & PreserveMask) | (NewFlags & ~PreserveMask);
 }
 
+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))
+    Sec.Type = SHT_PROGBITS;
+}
+
 static ElfType getOutputElfType(const Binary &Bin) {
   // Infer output ELF type from the input ELF object
   if (isa<ELFObjectFile<ELF32LE>>(Bin))
@@ -574,8 +587,7 @@ static Error handleArgs(const CopyConfig
         const SectionRename &SR = Iter->second;
         Sec.Name = SR.NewName;
         if (SR.NewFlags.hasValue())
-          Sec.Flags = setSectionFlagsPreserveMask(
-              Sec.Flags, getNewShfFlags(SR.NewFlags.getValue()));
+          setSectionFlagsAndType(Sec, SR.NewFlags.getValue());
       }
     }
   }
@@ -585,8 +597,7 @@ static Error handleArgs(const CopyConfig
       const auto Iter = Config.SetSectionFlags.find(Sec.Name);
       if (Iter != Config.SetSectionFlags.end()) {
         const SectionFlagsUpdate &SFU = Iter->second;
-        Sec.Flags = setSectionFlagsPreserveMask(Sec.Flags,
-                                                getNewShfFlags(SFU.NewFlags));
+        setSectionFlagsAndType(Sec, SFU.NewFlags);
       }
     }
   }




More information about the llvm-commits mailing list