[llvm-branch-commits] [lld] 93ad0ed - [ELF] Drop .rel[a].debug_gnu_pub{names, types} for --gdb-index --emit-relocs
Fangrui Song via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Jan 12 00:11:37 PST 2021
Author: Fangrui Song
Date: 2021-01-12T00:07:28-08:00
New Revision: 93ad0edf674125f19177054d8331a5e8910d3d98
URL: https://github.com/llvm/llvm-project/commit/93ad0edf674125f19177054d8331a5e8910d3d98
DIFF: https://github.com/llvm/llvm-project/commit/93ad0edf674125f19177054d8331a5e8910d3d98.diff
LOG: [ELF] Drop .rel[a].debug_gnu_pub{names,types} for --gdb-index --emit-relocs
Fixes PR48693: --emit-relocs keeps relocation sections. --gdb-index drops
.debug_gnu_pubnames and .debug_gnu_pubtypes but not their relocation sections.
This can cause a null pointer dereference in `getOutputSectionName`.
Also delete debug-gnu-pubnames.s which is covered by gdb-index.s
Reviewed By: grimar
Differential Revision: https://reviews.llvm.org/D94354
Added:
Modified:
lld/ELF/SyntheticSections.cpp
lld/test/ELF/gdb-index.s
Removed:
lld/test/ELF/debug-gnu-pubnames.s
################################################################################
diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index 9b5fb3f26c59..9a875bd7ec3e 100644
--- a/lld/ELF/SyntheticSections.cpp
+++ b/lld/ELF/SyntheticSections.cpp
@@ -2879,6 +2879,13 @@ template <class ELFT> GdbIndexSection *GdbIndexSection::create() {
else if (isec->name == ".debug_info")
files.insert(isec->file);
}
+ // Drop .rel[a].debug_gnu_pub{names,types} for --emit-relocs.
+ llvm::erase_if(inputSections, [](InputSectionBase *s) {
+ if (auto *isec = dyn_cast<InputSection>(s))
+ if (InputSectionBase *rel = isec->getRelocatedSection())
+ return !rel->isLive();
+ return !s->isLive();
+ });
std::vector<GdbChunk> chunks(files.size());
std::vector<std::vector<NameAttrEntry>> nameAttrs(files.size());
diff --git a/lld/test/ELF/debug-gnu-pubnames.s b/lld/test/ELF/debug-gnu-pubnames.s
deleted file mode 100644
index 51a289e52558..000000000000
--- a/lld/test/ELF/debug-gnu-pubnames.s
+++ /dev/null
@@ -1,18 +0,0 @@
-# REQUIRES: x86
-# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
-
-# RUN: ld.lld %t.o -o %t1.exe
-# RUN: llvm-readobj --sections %t1.exe | FileCheck %s
-# CHECK: .debug_gnu_pubnames
-# CHECK: .debug_gnu_pubtypes
-
-# RUN: ld.lld --gdb-index %t.o -o %t2.exe
-# RUN: llvm-readobj --sections %t2.exe | FileCheck %s --check-prefix=GDB
-# GDB-NOT: .debug_gnu_pubnames
-# GDB-NOT: .debug_gnu_pubtypes
-
-.section .debug_gnu_pubnames,"", at progbits
-.long 0
-
-.section .debug_gnu_pubtypes,"", at progbits
-.long 0
diff --git a/lld/test/ELF/gdb-index.s b/lld/test/ELF/gdb-index.s
index 546590ab359e..54a01a2c0d51 100644
--- a/lld/test/ELF/gdb-index.s
+++ b/lld/test/ELF/gdb-index.s
@@ -5,7 +5,14 @@
# RUN: llvm-objdump -d %t | FileCheck %s --check-prefix=DISASM
# RUN: llvm-dwarfdump -gdb-index %t | FileCheck %s --check-prefix=DWARF
-# RUN: llvm-readelf -sections %t | FileCheck %s --check-prefix=SECTION
+
+## Drop .debug_gnu_pubnames and .debug_gnu_pubtypes.
+## Also drop their relocation sections if --emit-relocs is specified.
+# RUN: ld.lld --gdb-index --emit-relocs %t1.o %t2.o -o %t1
+# RUN: llvm-readelf --sections %t1 | FileCheck %s --check-prefix=SECTION
+
+# SECTION-NOT: .debug_gnu_pubnames
+# SECTION-NOT: .debug_gnu_pubtypes
# RUN: llvm-mc -compress-debug-sections=zlib-gnu -filetype=obj -triple=x86_64-pc-linux \
# RUN: %p/Inputs/gdb-index.s -o %t2.o
@@ -46,8 +53,6 @@
# DWARF-NEXT: 1(0x8): 0x30000000
# DWARF-NEXT: 2(0x10): 0x90000000 0x90000001
-# SECTION-NOT: debug_gnu_pubnames
-
# RUN: ld.lld --gdb-index --no-gdb-index %t1.o %t2.o -o %t2
# RUN: llvm-readobj --sections %t2 | FileCheck -check-prefix=NOGDB %s
# NOGDB-NOT: Name: .gdb_index
@@ -111,7 +116,7 @@ entrypoint:
.section .debug_gnu_pubnames,"", at progbits
.long 0x1e
.value 0x2
-.long 0
+.long .debug_info
.long 0x33
.long 0x18
.byte 0x30
@@ -121,7 +126,7 @@ entrypoint:
.section .debug_gnu_pubtypes,"", at progbits
.long 0x17
.value 0x2
-.long 0
+.long .debug_info
.long 0x33
.long 0x2b
.byte 0x90
More information about the llvm-branch-commits
mailing list