[lld] 43753f8 - [ELF] Remove irrelevant SHT_INIT_ARRAY/SHT_FINI_ARRAY hack

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 25 14:23:10 PDT 2021


Author: Fangrui Song
Date: 2021-10-25T14:23:05-07:00
New Revision: 43753f8f9d6682c7e0295d82d8a6727041925be7

URL: https://github.com/llvm/llvm-project/commit/43753f8f9d6682c7e0295d82d8a6727041925be7
DIFF: https://github.com/llvm/llvm-project/commit/43753f8f9d6682c7e0295d82d8a6727041925be7.diff

LOG: [ELF] Remove irrelevant SHT_INIT_ARRAY/SHT_FINI_ARRAY hack

The hack is irrelevant for two reasons:

* binutils 2.24 is quite old and cannot handle R_X86_64_REX_GOTPCRELX from 2016 onwards anyway
* `canMergeToProgbits` allows combining SHT_INIT_ARRAY/SHT_FINI_ARRAY into SHT_PROGBITS

Added: 
    

Modified: 
    lld/ELF/InputSection.cpp
    lld/test/ELF/init-fini-progbits.s

Removed: 
    


################################################################################
diff  --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp
index 7730eab58d43..d6cc0fa5368a 100644
--- a/lld/ELF/InputSection.cpp
+++ b/lld/ELF/InputSection.cpp
@@ -117,32 +117,14 @@ static uint64_t getFlags(uint64_t flags) {
   return flags;
 }
 
-// GNU assembler 2.24 and LLVM 4.0.0's MC (the newest release as of
-// March 2017) fail to infer section types for sections starting with
-// ".init_array." or ".fini_array.". They set SHT_PROGBITS instead of
-// SHF_INIT_ARRAY. As a result, the following assembler directive
-// creates ".init_array.100" with SHT_PROGBITS, for example.
-//
-//   .section .init_array.100, "aw"
-//
-// This function forces SHT_{INIT,FINI}_ARRAY so that we can handle
-// incorrect inputs as if they were correct from the beginning.
-static uint64_t getType(uint64_t type, StringRef name) {
-  if (type == SHT_PROGBITS && name.startswith(".init_array."))
-    return SHT_INIT_ARRAY;
-  if (type == SHT_PROGBITS && name.startswith(".fini_array."))
-    return SHT_FINI_ARRAY;
-  return type;
-}
-
 template <class ELFT>
 InputSectionBase::InputSectionBase(ObjFile<ELFT> &file,
                                    const typename ELFT::Shdr &hdr,
                                    StringRef name, Kind sectionKind)
-    : InputSectionBase(&file, getFlags(hdr.sh_flags),
-                       getType(hdr.sh_type, name), hdr.sh_entsize, hdr.sh_link,
-                       hdr.sh_info, hdr.sh_addralign,
-                       getSectionContents(file, hdr), name, sectionKind) {
+    : InputSectionBase(&file, getFlags(hdr.sh_flags), hdr.sh_type,
+                       hdr.sh_entsize, hdr.sh_link, hdr.sh_info,
+                       hdr.sh_addralign, getSectionContents(file, hdr), name,
+                       sectionKind) {
   // We reject object files having insanely large alignments even though
   // they are allowed by the spec. I think 4GB is a reasonable limitation.
   // We might want to relax this in the future.

diff  --git a/lld/test/ELF/init-fini-progbits.s b/lld/test/ELF/init-fini-progbits.s
index dc8e251b139b..79d1c90b8766 100644
--- a/lld/test/ELF/init-fini-progbits.s
+++ b/lld/test/ELF/init-fini-progbits.s
@@ -5,9 +5,9 @@
 // RUN: llvm-readobj --sections %t.exe | FileCheck %s
 
 // CHECK:      Name: .init_array
-// CHECK-NEXT: Type: SHT_INIT_ARRAY
+// CHECK-NEXT: Type: SHT_PROGBITS
 // CHECK:      Name: .fini_array
-// CHECK-NEXT: Type: SHT_FINI_ARRAY
+// CHECK-NEXT: Type: SHT_PROGBITS
 
 .globl _start
 _start:


        


More information about the llvm-commits mailing list