[llvm-branch-commits] [llvm] 2c69f98 - [llvm-objcopy] Preserve .ARM.attributes section when stripping files

Tom Stellard via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Nov 7 17:53:43 PST 2019


Author: James Henderson
Date: 2019-11-07T17:42:06-08:00
New Revision: 2c69f98463a2cae9ea1f42285f6ac89b02dc8ec9

URL: https://github.com/llvm/llvm-project/commit/2c69f98463a2cae9ea1f42285f6ac89b02dc8ec9
DIFF: https://github.com/llvm/llvm-project/commit/2c69f98463a2cae9ea1f42285f6ac89b02dc8ec9.diff

LOG: [llvm-objcopy] Preserve .ARM.attributes section when stripping files

This works around a bug in Debian's patchset for glibc. The bug is
described in detail in the upstream debian bug:
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=943798, but the short
version of it is that glibc on any Debian based distro don't load
libraries unless it has a .ARM.attribute section.

Reviewed by: jhenderson, rupprecht, MaskRay, jakehehrlich

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

Patch by Tobias Hieta.

(cherry picked from commit fb4a55010ee9bd03720609c8542f770775576fc8)

Added: 
    llvm/test/tools/llvm-objcopy/ELF/strip-preserve-arm-attributes.test

Modified: 
    llvm/docs/CommandGuide/llvm-objcopy.rst
    llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp
    llvm/tools/llvm-objcopy/ObjcopyOpts.td
    llvm/tools/llvm-objcopy/StripOpts.td

Removed: 
    


################################################################################
diff  --git a/llvm/docs/CommandGuide/llvm-objcopy.rst b/llvm/docs/CommandGuide/llvm-objcopy.rst
index e113a82b6eea..bc589ae188fd 100644
--- a/llvm/docs/CommandGuide/llvm-objcopy.rst
+++ b/llvm/docs/CommandGuide/llvm-objcopy.rst
@@ -79,7 +79,8 @@ multiple file formats.
 .. option:: --strip-all, -S
 
  For ELF objects, remove from the output all symbols and non-alloc sections not
- within segments, except for .gnu.warning sections and the section name table.
+ within segments, except for .gnu.warning, .ARM.attribute sections and the
+ section name table.
 
  For COFF objects, remove all symbols, debug sections, and relocations from the
  output.

diff  --git a/llvm/test/tools/llvm-objcopy/ELF/strip-preserve-arm-attributes.test b/llvm/test/tools/llvm-objcopy/ELF/strip-preserve-arm-attributes.test
new file mode 100644
index 000000000000..2dcca66df1a6
--- /dev/null
+++ b/llvm/test/tools/llvm-objcopy/ELF/strip-preserve-arm-attributes.test
@@ -0,0 +1,25 @@
+## This test makes sure that --strip-all and --strip-all-gnu preserve
+## .ARM.attributes sections in ELF files. This is needed to maintain
+## compatibility for Ubuntu/Debian distributions on ARM.
+
+# RUN: yaml2obj %s > %t
+# RUN: llvm-objcopy --strip-all %t %t2
+# RUN: llvm-readobj --sections %t2 | FileCheck %s
+# RUN: llvm-objcopy --strip-all-gnu %t %t3
+# RUN: llvm-readobj --sections %t3 | FileCheck %s
+# RUN: llvm-strip %t -o %t4
+# RUN: cmp %t4 %t2
+# RUN: llvm-strip --strip-all-gnu %t -o %t5
+# RUN: cmp %t5 %t3
+
+!ELF
+FileHeader:
+  Class:           ELFCLASS32
+  Data:            ELFDATA2LSB
+  Type:            ET_DYN
+  Machine:         EM_ARM
+Sections:
+  - Name:            .ARM.attributes
+    Type:            SHT_ARM_ATTRIBUTES
+
+# CHECK: Name: .ARM.attributes

diff  --git a/llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp b/llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp
index b366c6e55987..2e25a47dde01 100644
--- a/llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp
+++ b/llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp
@@ -504,6 +504,12 @@ static Error replaceAndRemoveSections(const CopyConfig &Config, Object &Obj) {
         return false;
       if (StringRef(Sec.Name).startswith(".gnu.warning"))
         return false;
+      // We keep the .ARM.attribute section to maintain compatibility
+      // with Debian derived distributions. This is a bug in their
+      // patchset as documented here:
+      // https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=943798
+      if (Sec.Type == SHT_ARM_ATTRIBUTES)
+        return false;
       if (Sec.ParentSegment != nullptr)
         return false;
       return (Sec.Flags & SHF_ALLOC) == 0;

diff  --git a/llvm/tools/llvm-objcopy/ObjcopyOpts.td b/llvm/tools/llvm-objcopy/ObjcopyOpts.td
index 5fce4fbde539..757d7e97958d 100644
--- a/llvm/tools/llvm-objcopy/ObjcopyOpts.td
+++ b/llvm/tools/llvm-objcopy/ObjcopyOpts.td
@@ -112,7 +112,8 @@ defm set_section_flags
 
 def strip_all : Flag<["--"], "strip-all">,
                 HelpText<"Remove non-allocated sections outside segments. "
-                         ".gnu.warning* sections are not removed">;
+                         ".gnu.warning* and .ARM.attribute sections are not "
+                         "removed">;
 def S : Flag<["-"], "S">, Alias<strip_all>;
 def strip_all_gnu : Flag<["--"], "strip-all-gnu">,
                     HelpText<"Compatible with GNU objcopy's --strip-all">;

diff  --git a/llvm/tools/llvm-objcopy/StripOpts.td b/llvm/tools/llvm-objcopy/StripOpts.td
index 1d06bb3dfb38..a80a91e744a9 100644
--- a/llvm/tools/llvm-objcopy/StripOpts.td
+++ b/llvm/tools/llvm-objcopy/StripOpts.td
@@ -40,7 +40,8 @@ def p : Flag<["-"], "p">, Alias<preserve_dates>;
 
 def strip_all : Flag<["--"], "strip-all">,
                 HelpText<"Remove non-allocated sections outside segments. "
-                         ".gnu.warning* sections are not removed">;
+                          ".gnu.warning* and .ARM.attribute sections are not "
+                          "removed">;
 def s : Flag<["-"], "s">, Alias<strip_all>;
 def no_strip_all : Flag<["--"], "no-strip-all">,
                    HelpText<"Disable --strip-all">;


        


More information about the llvm-branch-commits mailing list