[PATCH] D64880: ELF: Allow forward references to linked sections.

Peter Collingbourne via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 17 12:43:33 PDT 2019


pcc created this revision.
pcc added reviewers: ruiu, MaskRay, grimar, peter.smith.
Herald added subscribers: arichardson, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.

It's possible to create IR that uses !associated to refer to a global that
appears later in the module, which can result in these types of forward
references being generated. Unfortunately our assembler does not currently
accept the resulting .s so I needed to use yaml2obj to test this.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D64880

Files:
  lld/ELF/InputFiles.cpp
  lld/test/ELF/linkorder-forward-ref.test


Index: lld/test/ELF/linkorder-forward-ref.test
===================================================================
--- /dev/null
+++ lld/test/ELF/linkorder-forward-ref.test
@@ -0,0 +1,22 @@
+# REQUIRES: x86
+# RUN: yaml2obj %s -o %t.o
+# RUN: ld.lld %t.o -o %t
+# RUN: llvm-readelf -S %t | FileCheck %s
+
+# CHECK: .linkorder
+# CHECK: .text
+
+--- !ELF
+FileHeader:
+  Class:           ELFCLASS64
+  Data:            ELFDATA2LSB
+  Type:            ET_REL
+  Machine:         EM_X86_64
+Sections:
+  - Name:          .linkorder
+    Type:          SHT_PROGBITS
+    Flags:         [ SHF_ALLOC, SHF_EXECINSTR, SHF_LINK_ORDER ]
+    Link:          2
+  - Name:          .text
+    Type:          SHT_PROGBITS
+    Flags:         [ SHF_ALLOC, SHF_EXECINSTR ]
Index: lld/ELF/InputFiles.cpp
===================================================================
--- lld/ELF/InputFiles.cpp
+++ lld/ELF/InputFiles.cpp
@@ -652,6 +652,12 @@
     default:
       this->sections[i] = createInputSection(sec);
     }
+  }
+
+  for (size_t i = 0, e = objSections.size(); i < e; i++) {
+    if (this->sections[i] == &InputSection::discarded)
+      continue;
+    const Elf_Shdr &sec = objSections[i];
 
     // .ARM.exidx sections have a reverse dependency on the InputSection they
     // have a SHF_LINK_ORDER dependency, this is identified by the sh_link.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D64880.210396.patch
Type: text/x-patch
Size: 1344 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190717/9de45ff5/attachment.bin>


More information about the llvm-commits mailing list