[lld] cf70a1e - [ELF] .llvm.sympart: support CREL

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 16 13:12:50 PDT 2024


Author: Fangrui Song
Date: 2024-09-16T13:12:45-07:00
New Revision: cf70a1ee815d11ae52c4a5d034e65a7a713bd06c

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

LOG: [ELF] .llvm.sympart: support CREL

When both CREL and the experimental lld partitions feature are enabled,
the relocation section may look like .crel.llvm_sympart.f1, and
`rels.relas` is empty. While here, support relocation sections with zero
entry.

Added: 
    

Modified: 
    lld/ELF/Driver.cpp
    lld/test/ELF/partitions.s

Removed: 
    


################################################################################
diff  --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index 34b146759bea6f..3712d28f227f69 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -2438,11 +2438,18 @@ static void readSymbolPartitionSection(InputSectionBase *s) {
   // Read the relocation that refers to the partition's entry point symbol.
   Symbol *sym;
   const RelsOrRelas<ELFT> rels = s->template relsOrRelas<ELFT>();
-  if (rels.areRelocsRel())
-    sym = &s->file->getRelocTargetSym(rels.rels[0]);
+  auto readEntry = [](InputFile *file, const auto &rels) -> Symbol * {
+    for (const auto &rel : rels)
+      return &file->getRelocTargetSym(rel);
+    return nullptr;
+  };
+  if (rels.areRelocsCrel())
+    sym = readEntry(s->file, rels.crels);
+  else if (rels.areRelocsRel())
+    sym = readEntry(s->file, rels.rels);
   else
-    sym = &s->file->getRelocTargetSym(rels.relas[0]);
-  if (!isa<Defined>(sym) || !sym->includeInDynsym())
+    sym = readEntry(s->file, rels.relas);
+  if (!isa_and_nonnull<Defined>(sym) || !sym->includeInDynsym())
     return;
 
   StringRef partName = reinterpret_cast<const char *>(s->content().data());

diff  --git a/lld/test/ELF/partitions.s b/lld/test/ELF/partitions.s
index f875a9cb4906c2..103094e081a37a 100644
--- a/lld/test/ELF/partitions.s
+++ b/lld/test/ELF/partitions.s
@@ -3,7 +3,7 @@
 // RUN: ld.lld %t.o -o %t --export-dynamic --gc-sections -z max-page-size=65536
 // RUN: llvm-readelf -S -s %t | FileCheck %s
 
-// RUN: llvm-mc %s -o %t.o -filetype=obj --triple=aarch64
+// RUN: llvm-mc %s -o %t.o -filetype=obj --triple=aarch64 --crel
 // RUN: ld.lld %t.o -o %t --export-dynamic --gc-sections
 // RUN: llvm-readelf -S -s %t | FileCheck %s
 


        


More information about the llvm-commits mailing list