[lld] r321600 - [ELF] - Add missing dynamic tags when producing output with IRelative relocations only.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Sat Dec 30 23:42:54 PST 2017


Author: grimar
Date: Sat Dec 30 23:42:54 2017
New Revision: 321600

URL: http://llvm.org/viewvc/llvm-project?rev=321600&view=rev
Log:
[ELF] - Add missing dynamic tags when producing output with IRelative relocations only.

This is "Bug 35751 - .dynamic relocation entries omitted if output
contains only IFUNC relocations"

We have InX::RelaPlt and InX::RelaIPlt synthetic sections for PLT relocations.
They are usually live in rela.plt section. Problem appears when InX::RelaPlt
section is empty. In that case we did not produce normal set of dynamic tags
required, because logic was written in the way assuming we always have
non-IRelative relocations in rela.plt.

Patch fixes the issue.

Differential revision: https://reviews.llvm.org/D41592

Added:
    lld/trunk/test/ELF/gnu-ifunc-dyntags.s
Modified:
    lld/trunk/ELF/SyntheticSections.cpp

Modified: lld/trunk/ELF/SyntheticSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.cpp?rev=321600&r1=321599&r2=321600&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.cpp (original)
+++ lld/trunk/ELF/SyntheticSections.cpp Sat Dec 30 23:42:54 2017
@@ -1081,7 +1081,13 @@ template <class ELFT> void DynamicSectio
         addInt(IsRela ? DT_RELACOUNT : DT_RELCOUNT, NumRelativeRels);
     }
   }
-  if (!InX::RelaPlt->empty()) {
+  // .rel[a].plt section usually consists of two parts, containing plt and
+  // iplt relocations. It is possible to have only iplt relocations in the
+  // output. In that case RelaPlt is empty and have zero offset, the same offset
+  // as RelaIplt have. And we still want to emit proper dynamic tags for that
+  // case, so here we always use RelaPlt as marker for the begining of
+  // .rel[a].plt section.
+  if (InX::RelaPlt->getParent()->Live) {
     addInSec(DT_JMPREL, InX::RelaPlt);
     addSize(DT_PLTRELSZ, InX::RelaPlt->getParent());
     switch (Config->EMachine) {

Added: lld/trunk/test/ELF/gnu-ifunc-dyntags.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/gnu-ifunc-dyntags.s?rev=321600&view=auto
==============================================================================
--- lld/trunk/test/ELF/gnu-ifunc-dyntags.s (added)
+++ lld/trunk/test/ELF/gnu-ifunc-dyntags.s Sat Dec 30 23:42:54 2017
@@ -0,0 +1,41 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
+# RUN: ld.lld -pie %t.o -o %tout
+# RUN: llvm-objdump -section-headers %tout | FileCheck %s
+# RUN: llvm-readobj -dynamic-table -r %tout | FileCheck %s --check-prefix=TAGS
+
+## Check we produce DT_PLTREL/DT_JMPREL/DT_PLTGOT and DT_PLTRELSZ tags
+## when there are no other relocations except R_*_IRELATIVE.
+
+# CHECK:  Name          Size      Address
+# CHECK:  .rela.plt   00000030 0000000000000210
+# CHECK:  .got.plt    00000010 0000000000002000
+
+# TAGS:      Relocations [
+# TAGS-NEXT:   Section {{.*}} .rela.plt {
+# TAGS-NEXT:     R_X86_64_IRELATIVE
+# TAGS-NEXT:     R_X86_64_IRELATIVE
+# TAGS-NEXT:   }
+# TAGS-NEXT: ]
+
+# TAGS:   Tag                Type                 Name/Value
+# TAGS:   0x0000000000000017 JMPREL               0x210
+# TAGS:   0x0000000000000002 PLTRELSZ             48
+# TAGS:   0x0000000000000003 PLTGOT               0x2000
+# TAGS:   0x0000000000000014 PLTREL               RELA
+
+.text
+.type foo STT_GNU_IFUNC
+.globl foo
+foo:
+ ret
+
+.type bar STT_GNU_IFUNC
+.globl bar
+bar:
+ ret
+
+.globl _start
+_start:
+ call foo
+ call bar




More information about the llvm-commits mailing list