Skip to content

Commit 97e160b

Browse files
author
apple-llvm-mt
committed
Merge root: Revert Add github lockdown app to auto-close pull requests.
apple-llvm-split-dir: -
2 parents 037c284 + c3ab38e commit 97e160b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+774
-219
lines changed

.github/lockdown.yml

Lines changed: 0 additions & 33 deletions
This file was deleted.

debuginfo-tests/nrvo-string.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
// RUN: %test_debuginfo %s %t.out
88
//
99
// PR34513
10+
void __attribute__((noinline)) stop() {}
1011

1112
struct string {
1213
string() {}
@@ -17,7 +18,8 @@ struct string {
1718
string get_string() {
1819
string unused;
1920
string result = 3;
20-
// DEBUGGER: break 21
21+
// DEBUGGER: break 22
22+
stop();
2123
return result;
2224
}
2325
void some_function(int) {}
@@ -32,7 +34,8 @@ string2 get_string2() {
3234
some_function(result.i);
3335
// Test that the debugger can get the value of result after another
3436
// function is called.
35-
// DEBUGGER: break 35
37+
// DEBUGGER: break 38
38+
stop();
3639
return result;
3740
}
3841
int main() {

lld/COFF/Config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ struct Configuration {
115115
// Symbols in this set are considered as live by the garbage collector.
116116
std::vector<Symbol *> GCRoot;
117117

118-
std::set<StringRef> NoDefaultLibs;
118+
std::set<std::string> NoDefaultLibs;
119119
bool NoDefaultLibAll = false;
120120

121121
// True if we are creating a DLL.

lld/COFF/Driver.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ void LinkerDriver::parseDirectives(InputFile *File) {
356356
parseMerge(Arg->getValue());
357357
break;
358358
case OPT_nodefaultlib:
359-
Config->NoDefaultLibs.insert(doFindLib(Arg->getValue()));
359+
Config->NoDefaultLibs.insert(doFindLib(Arg->getValue()).lower());
360360
break;
361361
case OPT_section:
362362
parseSection(Arg->getValue());
@@ -457,7 +457,7 @@ Optional<StringRef> LinkerDriver::findLib(StringRef Filename) {
457457
return None;
458458

459459
StringRef Path = doFindLib(Filename);
460-
if (Config->NoDefaultLibs.count(Path))
460+
if (Config->NoDefaultLibs.count(Path.lower()))
461461
return None;
462462

463463
if (Optional<sys::fs::UniqueID> ID = getUniqueID(Path))
@@ -1240,7 +1240,7 @@ void LinkerDriver::link(ArrayRef<const char *> ArgsArr) {
12401240

12411241
// Handle /nodefaultlib:<filename>
12421242
for (auto *Arg : Args.filtered(OPT_nodefaultlib))
1243-
Config->NoDefaultLibs.insert(doFindLib(Arg->getValue()));
1243+
Config->NoDefaultLibs.insert(doFindLib(Arg->getValue()).lower());
12441244

12451245
// Handle /nodefaultlib
12461246
if (Args.hasArg(OPT_nodefaultlib_all))

lld/ELF/DWARF.cpp

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -92,21 +92,20 @@ LLDDwarfObj<ELFT>::findAux(const InputSectionBase &Sec, uint64_t Pos,
9292
const typename ELFT::Sym &Sym = File->template getELFSyms<ELFT>()[SymIndex];
9393
uint32_t SecIndex = File->getSectionIndex(Sym);
9494

95-
// Broken debug info can point to a non-Defined symbol.
96-
auto *DR = dyn_cast<Defined>(&File->getRelocTargetSym(Rel));
97-
if (!DR) {
98-
RelType Type = Rel.getType(Config->IsMips64EL);
99-
if (Type != Target->NoneRel)
100-
error(toString(File) + ": relocation " + lld::toString(Type) + " at 0x" +
101-
llvm::utohexstr(Rel.r_offset) + " has unsupported target");
102-
return None;
103-
}
104-
uint64_t Val = DR->Value;
95+
// An undefined symbol may be a symbol defined in a discarded section. We
96+
// shall still resolve it. This is important for --gdb-index: the end address
97+
// offset of an entry in .debug_ranges is relocated. If it is not resolved,
98+
// its zero value will terminate the decoding of .debug_ranges prematurely.
99+
Symbol &S = File->getRelocTargetSym(Rel);
100+
uint64_t Val = 0;
101+
if (auto *DR = dyn_cast<Defined>(&S)) {
102+
Val = DR->Value;
105103

106-
// FIXME: We should be consistent about always adding the file
107-
// offset or not.
108-
if (DR->Section->Flags & ELF::SHF_ALLOC)
109-
Val += cast<InputSection>(DR->Section)->getOffsetInFile();
104+
// FIXME: We should be consistent about always adding the file
105+
// offset or not.
106+
if (DR->Section->Flags & ELF::SHF_ALLOC)
107+
Val += cast<InputSection>(DR->Section)->getOffsetInFile();
108+
}
110109

111110
DataRefImpl D;
112111
D.p = getAddend<ELFT>(Rel);

lld/ELF/InputFiles.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,6 +1080,9 @@ template <class ELFT> void ObjFile<ELFT>::initializeSymbols() {
10801080

10811081
if (ESym.st_shndx == SHN_UNDEF)
10821082
this->Symbols[I] = make<Undefined>(this, Name, Binding, StOther, Type);
1083+
else if (Sec == &InputSection::Discarded)
1084+
this->Symbols[I] = make<Undefined>(this, Name, Binding, StOther, Type,
1085+
/*DiscardedSecIdx=*/SecIdx);
10831086
else
10841087
this->Symbols[I] =
10851088
make<Defined>(this, Name, Binding, StOther, Type, Value, Size, Sec);

lld/ELF/InputSection.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,8 @@ void InputSection::copyRelocations(uint8_t *Buf, ArrayRef<RelTy> Rels) {
412412

413413
for (const RelTy &Rel : Rels) {
414414
RelType Type = Rel.getType(Config->IsMips64EL);
415-
Symbol &Sym = getFile<ELFT>()->getRelocTargetSym(Rel);
415+
const ObjFile<ELFT> *File = getFile<ELFT>();
416+
Symbol &Sym = File->getRelocTargetSym(Rel);
416417

417418
auto *P = reinterpret_cast<typename ELFT::Rela *>(Buf);
418419
Buf += sizeof(RelTy);
@@ -435,10 +436,23 @@ void InputSection::copyRelocations(uint8_t *Buf, ArrayRef<RelTy> Rels) {
435436
// .eh_frame is horribly special and can reference discarded sections. To
436437
// avoid having to parse and recreate .eh_frame, we just replace any
437438
// relocation in it pointing to discarded sections with R_*_NONE, which
438-
// hopefully creates a frame that is ignored at runtime.
439+
// hopefully creates a frame that is ignored at runtime. Also, don't warn
440+
// on .gcc_except_table and debug sections.
441+
//
442+
// See the comment in maybeReportUndefined for PPC64 .toc .
439443
auto *D = dyn_cast<Defined>(&Sym);
440444
if (!D) {
441-
error("STT_SECTION symbol should be defined");
445+
if (!Sec->Name.startswith(".debug") &&
446+
!Sec->Name.startswith(".zdebug") && Sec->Name != ".eh_frame" &&
447+
Sec->Name != ".gcc_except_table" && Sec->Name != ".toc") {
448+
uint32_t SecIdx = cast<Undefined>(Sym).DiscardedSecIdx;
449+
Elf_Shdr_Impl<ELFT> Sec =
450+
CHECK(File->getObj().sections(), File)[SecIdx];
451+
warn("relocation refers to a discarded section: " +
452+
CHECK(File->getObj().getSectionName(&Sec), File) +
453+
"\n>>> referenced by " + getObjMsg(P->r_offset));
454+
}
455+
P->setSymbolAndType(0, 0, false);
442456
continue;
443457
}
444458
SectionBase *Section = D->Section->Repl;

lld/ELF/Relocations.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -653,9 +653,17 @@ static std::string maybeReportDiscarded(Undefined &Sym) {
653653
return "";
654654
ArrayRef<Elf_Shdr_Impl<ELFT>> ObjSections =
655655
CHECK(File->getObj().sections(), File);
656-
std::string Msg =
657-
"relocation refers to a symbol in a discarded section: " + toString(Sym) +
658-
"\n>>> defined in " + toString(File);
656+
657+
std::string Msg;
658+
if (Sym.Type == ELF::STT_SECTION) {
659+
Msg = "relocation refers to a discarded section: ";
660+
Msg += CHECK(
661+
File->getObj().getSectionName(&ObjSections[Sym.DiscardedSecIdx]), File);
662+
} else {
663+
Msg = "relocation refers to a symbol in a discarded section: " +
664+
toString(Sym);
665+
}
666+
Msg += "\n>>> defined in " + toString(File);
659667

660668
Elf_Shdr_Impl<ELFT> ELFSec = ObjSections[Sym.DiscardedSecIdx - 1];
661669
if (ELFSec.sh_type != SHT_GROUP)

lld/ELF/Symbols.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,11 @@ static uint64_t getSymVA(const Symbol &Sym, int64_t &Addend) {
4848
auto &D = cast<Defined>(Sym);
4949
SectionBase *IS = D.Section;
5050

51-
// According to the ELF spec reference to a local symbol from outside
52-
// the group are not allowed. Unfortunately .eh_frame breaks that rule
53-
// and must be treated specially. For now we just replace the symbol with
54-
// 0.
55-
if (IS == &InputSection::Discarded)
56-
return 0;
57-
5851
// This is an absolute symbol.
5952
if (!IS)
6053
return D.Value;
6154

55+
assert(IS != &InputSection::Discarded);
6256
IS = IS->Repl;
6357

6458
uint64_t Offset = D.Value;

lld/test/COFF/nodefaultlib.test

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,10 @@ CHECK3-NEXT: >>> referenced by {{.*}}hello64.obj:(main)
2929

3030
# RUN: env LIB=%T lld-link /out:%t.exe /entry:main \
3131
# RUN: /subsystem:console hello64.obj /defaultlib:std64.lib
32+
33+
MSVC stamps uppercase references in OBJ directives, thus ensure that passing lowercase 'libcmt' and 'oldnames' to /nodefaultlib works.
34+
# RUN: lld-link %S/Inputs/precomp.obj %S/Inputs/precomp-a.obj %S/Inputs/precomp-b.obj /nodefaultlib:libcmt /nodefaultlib:oldnames /entry:main /debug /pdb:%t.pdb /out:%t.exe /opt:ref /opt:icf
35+
# RUN: llvm-pdbutil dump -modules %t.pdb | FileCheck %s -check-prefix UPPERCASE
36+
37+
UPPERCASE-NOT: OLDNAMES
38+
UPPERCASE-NOT: LIBCMT
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
.section .text.bar1,"aG",@progbits,group,comdat
1+
.global bar, _start
22

3-
.section .text.bar2
4-
.global bar
5-
bar:
6-
.quad .text.bar1
3+
.section .text.foo,"aG",@progbits,group,comdat
4+
5+
.section .text
6+
_start:
7+
.quad .text.foo
8+
.quad bar

lld/test/ELF/comdat-discarded-error.s

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,24 @@
55
# RUN: echo '.section .text.foo,"axG",@progbits,foo,comdat; .globl bar; bar:' |\
66
# RUN: llvm-mc -filetype=obj -triple=x86_64 - -o %t3.o
77

8-
# RUN: not ld.lld %t1.o %t2.o %t3.o -o /dev/null 2>&1 | FileCheck %s
8+
# RUN: not ld.lld %t2.o %t3.o %t1.o -o /dev/null 2>&1 | FileCheck %s
99

1010
# CHECK: error: relocation refers to a symbol in a discarded section: bar
1111
# CHECK-NEXT: >>> defined in {{.*}}3.o
1212
# CHECK-NEXT: >>> section group signature: foo
1313
# CHECK-NEXT: >>> prevailing definition is in {{.*}}2.o
1414
# CHECK-NEXT: >>> referenced by {{.*}}1.o:(.text+0x1)
1515

16+
# CHECK: error: relocation refers to a discarded section: .text.foo
17+
# CHECK-NEXT: >>> defined in {{.*}}1.o
18+
# CHECK-NEXT: >>> section group signature: foo
19+
# CHECK-NEXT: >>> prevailing definition is in {{.*}}2.o
20+
# CHECK-NEXT: >>> referenced by {{.*}}1.o:(.data+0x0)
21+
1622
.globl _start
1723
_start:
1824
jmp bar
25+
26+
.section .text.foo,"axG",@progbits,foo,comdat
27+
.data
28+
.quad .text.foo
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# REQUIRES: x86
2+
# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o
3+
# RUN: ld.lld --gdb-index %t.o %t.o -o %t
4+
5+
## .debug_info has a relocation to .text.foo . The second %t.o is discarded.
6+
## Check we don't error on the relocation.
7+
# CHECK: .rela.debug_info {
8+
# CHECK-NEXT: 0xC R_X86_64_64 .text.foo 0x0
9+
10+
.section .text.foo,"axG",@progbits,foo,comdat
11+
.globl foo
12+
.Lfunc_begin0:
13+
foo:
14+
ret
15+
.Lfunc_end0:
16+
17+
.section .debug_abbrev,"",@progbits
18+
.byte 1 # Abbreviation Code
19+
.byte 17 # DW_TAG_compile_unit
20+
.byte 1 # DW_CHILDREN_yes
21+
.byte 17 # DW_AT_low_pc
22+
.byte 1 # DW_FORM_addr
23+
.byte 18 # DW_AT_high_pc
24+
.byte 6 # DW_FORM_data4
25+
.ascii "\264B" # DW_AT_GNU_pubnames
26+
.byte 25 # DW_FORM_flag_present
27+
.byte 0 # EOM(1)
28+
.byte 0 # EOM(2)
29+
.byte 2 # Abbreviation Code
30+
.byte 46 # DW_TAG_subprogram
31+
.byte 0 # DW_CHILDREN_no
32+
.byte 3 # DW_AT_name
33+
.byte 8 # DW_FORM_string
34+
.byte 0 # EOM(1)
35+
.byte 0 # EOM(2)
36+
.byte 0
37+
38+
.section .debug_info,"",@progbits
39+
.Lcu_begin0:
40+
.long .Lcu_end0 - .Lcu_begin0 - 4
41+
.short 4 # DWARF version number
42+
.long 0 # Offset Into Abbrev. Section
43+
.byte 4 # Address Size
44+
.Ldie0:
45+
.byte 1 # Abbrev [1] DW_TAG_compile_unit
46+
.quad .Lfunc_begin0 # DW_AT_low_pc
47+
.long .Lfunc_end0 - .Lfunc_begin0 # DW_AT_high_pc
48+
.byte 2 # Abbrev [2] DW_TAG_subprogram
49+
.asciz "foo" # DW_AT_name
50+
.byte 0
51+
.Lcu_end0:
52+
53+
.section .debug_gnu_pubnames,"",@progbits
54+
.long .LpubNames_end0 - .LpubNames_begin0
55+
.LpubNames_begin0:
56+
.short 2 # Version
57+
.long .Lcu_begin0 # CU Offset
58+
.long .Lcu_end0 - .Lcu_begin0
59+
.long .Ldie0 - .Lcu_begin0
60+
.byte 48 # Attributes: FUNCTION, EXTERNAL
61+
.asciz "foo" # External Name
62+
.long 0
63+
.LpubNames_end0:

lld/test/ELF/comdat-discarded-reloc.s

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,42 @@
11
# REQUIRES: x86
22
# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
33
# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/comdat-discarded-reloc.s -o %t2.o
4-
# RUN: ld.lld -gc-sections %t.o %t2.o -o %t
4+
# RUN: ld.lld -gc-sections --noinhibit-exec %t2.o %t.o -o /dev/null
5+
# RUN: ld.lld -r %t2.o %t.o -o %t 2>&1 | FileCheck --check-prefix=WARN %s
6+
# RUN: llvm-readobj -r %t | FileCheck --check-prefix=RELOC %s
57

68
## ELF spec doesn't allow a relocation to point to a deduplicated
79
## COMDAT section. Unfortunately this happens in practice (e.g. .eh_frame)
810
## Test case checks we do not crash.
911

10-
.global bar, _start
12+
# WARN: warning: relocation refers to a discarded section: .text.bar1
13+
# WARN-NEXT: >>> referenced by {{.*}}.o:(.rela.text.bar2+0x0)
14+
# WARN-NOT: warning
1115

12-
.section .text.foo,"aG",@progbits,group,comdat
16+
# RELOC: .rela.eh_frame {
17+
# RELOC-NEXT: R_X86_64_NONE
18+
# RELOC-NEXT: }
19+
# RELOC-NEXT: .rela.debug_foo {
20+
# RELOC-NEXT: R_X86_64_NONE
21+
# RELOC-NEXT: }
22+
# RELOC-NEXT: .rela.gcc_except_table {
23+
# RELOC-NEXT: R_X86_64_NONE
24+
# RELOC-NEXT: }
1325

14-
.section .text
15-
_start:
16-
.quad .text.foo
17-
.quad bar
26+
.section .text.bar1,"aG",@progbits,group,comdat
27+
28+
## .text.bar1 in this file is discarded. Warn on the relocation.
29+
.section .text.bar2,"ax"
30+
.globl bar
31+
bar:
32+
.quad .text.bar1
33+
34+
## Don't warn on .eh_frame, .debug*, .zdebug*, or .gcc_except_table
35+
.section .eh_frame,"a"
36+
.quad .text.bar1
37+
38+
.section .debug_foo
39+
.quad .text.bar1
40+
41+
.section .gcc_except_table,"a"
42+
.quad .text.bar1

0 commit comments

Comments
 (0)