Skip to content

Commit b506a0d

Browse files
authored
Merge pull request #808 from apple/upstream-with-swift
Merge upstream-with-swift into stable branch to match stable merge on clang/compiler-rt/llvm apple-llvm-split-commit: a5cac96cb2861b5b818cc280911180a0329f1205 apple-llvm-split-dir: lldb/
2 parents 2092108 + 6c54f87 commit b506a0d

File tree

1,546 files changed

+46138
-40126
lines changed

Some content is hidden

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

1,546 files changed

+46138
-40126
lines changed

libcxxabi/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@ set(LIBCXXABI_LIBCXX_LIBRARY_PATH "" CACHE PATH "The path to libc++ library.")
8484
option(LIBCXXABI_ENABLE_SHARED "Build libc++abi as a shared library." ON)
8585
option(LIBCXXABI_ENABLE_STATIC "Build libc++abi as a static library." ON)
8686

87+
cmake_dependent_option(LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_STATIC_LIBRARY
88+
"Statically link the LLVM unwinder to static library" ON
89+
"LIBCXXABI_ENABLE_STATIC_UNWINDER;LIBCXXABI_ENABLE_STATIC" OFF)
90+
cmake_dependent_option(LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_SHARED_LIBRARY
91+
"Statically link the LLVM unwinder to shared library" ON
92+
"LIBCXXABI_ENABLE_STATIC_UNWINDER;LIBCXXABI_ENABLE_SHARED" OFF)
93+
8794
option(LIBCXXABI_BAREMETAL "Build libc++abi for baremetal targets." OFF)
8895
# The default terminate handler attempts to demangle uncaught exceptions, which
8996
# causes extra I/O and demangling code to be pulled in.

libcxxabi/src/CMakeLists.txt

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,19 @@ if (LIBCXXABI_USE_LLVM_UNWINDER)
6161
# Prefer using the in-tree version of libunwind, either shared or static. If
6262
# none are found fall back to using -lunwind.
6363
# FIXME: Is it correct to prefer the static version of libunwind?
64-
if (NOT LIBCXXABI_ENABLE_STATIC_UNWINDER AND (TARGET unwind_shared OR HAVE_LIBUNWIND))
65-
list(APPEND LIBCXXABI_LIBRARIES unwind_shared)
66-
elseif (LIBCXXABI_ENABLE_STATIC_UNWINDER AND (TARGET unwind_static OR HAVE_LIBUNWIND))
67-
list(APPEND LIBCXXABI_LIBRARIES unwind_static)
64+
if (NOT LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_SHARED_LIBRARY AND (TARGET unwind_shared OR HAVE_LIBUNWIND))
65+
list(APPEND LIBCXXABI_SHARED_LIBRARIES unwind_shared)
66+
elseif (LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_SHARED_LIBRARY AND (TARGET unwind_static OR HAVE_LIBUNWIND))
67+
list(APPEND LIBCXXABI_SHARED_LIBRARIES unwind_static)
6868
else()
69-
list(APPEND LIBCXXABI_LIBRARIES unwind)
69+
list(APPEND LIBCXXABI_SHARED_LIBRARIES unwind)
70+
endif()
71+
if (NOT LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_STATIC_LIBRARY AND (TARGET unwind_shared OR HAVE_LIBUNWIND))
72+
list(APPEND LIBCXXABI_STATIC_LIBRARIES unwind_shared)
73+
elseif (LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_STATIC_LIBRARY AND (TARGET unwind_static OR HAVE_LIBUNWIND))
74+
# We handle this by directly merging libunwind objects into libc++abi.
75+
else()
76+
list(APPEND LIBCXXABI_STATIC_LIBRARIES unwind)
7077
endif()
7178
else()
7279
add_library_flags_if(LIBCXXABI_HAS_GCC_S_LIB gcc_s)
@@ -130,7 +137,7 @@ if (LIBCXXABI_ENABLE_SHARED)
130137
if(COMMAND llvm_setup_rpath)
131138
llvm_setup_rpath(cxxabi_shared)
132139
endif()
133-
target_link_libraries(cxxabi_shared ${LIBCXXABI_LIBRARIES})
140+
target_link_libraries(cxxabi_shared ${LIBCXXABI_LIBRARIES} ${LIBCXXABI_SHARED_LIBRARIES})
134141
set_target_properties(cxxabi_shared
135142
PROPERTIES
136143
CXX_EXTENSIONS
@@ -155,13 +162,13 @@ endif()
155162
# Build the static library.
156163
if (LIBCXXABI_ENABLE_STATIC)
157164
set(cxxabi_static_sources $<TARGET_OBJECTS:cxxabi_objects>)
158-
if (LIBCXXABI_USE_LLVM_UNWINDER AND LIBCXXABI_ENABLE_STATIC_UNWINDER)
165+
if (LIBCXXABI_USE_LLVM_UNWINDER AND LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_STATIC_LIBRARY)
159166
if (TARGET unwind_static OR HAVE_LIBUNWIND)
160167
list(APPEND cxxabi_static_sources $<TARGET_OBJECTS:unwind_objects>)
161168
endif()
162169
endif()
163170
add_library(cxxabi_static STATIC ${cxxabi_static_sources})
164-
target_link_libraries(cxxabi_static ${LIBCXXABI_LIBRARIES})
171+
target_link_libraries(cxxabi_static ${LIBCXXABI_LIBRARIES} ${LIBCXXABI_STATIC_LIBRARIES})
165172
set_target_properties(cxxabi_static
166173
PROPERTIES
167174
CXX_EXTENSIONS

lld/ELF/Arch/Hexagon.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ RelExpr Hexagon::getRelExpr(RelType Type, const Symbol &S,
5454
const uint8_t *Loc) const {
5555
switch (Type) {
5656
case R_HEX_B15_PCREL:
57+
case R_HEX_B15_PCREL_X:
5758
case R_HEX_B22_PCREL:
5859
case R_HEX_B22_PCREL_X:
5960
case R_HEX_B32_PCREL_X:
@@ -72,6 +73,9 @@ void Hexagon::relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const {
7273
case R_HEX_B15_PCREL:
7374
or32le(Loc, applyMask(0x00df20fe, Val >> 2));
7475
break;
76+
case R_HEX_B15_PCREL_X:
77+
or32le(Loc, applyMask(0x00df20fe, Val & 0x3f));
78+
break;
7579
case R_HEX_B22_PCREL:
7680
or32le(Loc, applyMask(0x1ff3ffe, Val >> 2));
7781
break;

lld/ELF/SyntheticSections.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,13 @@ template <class ELFT> void MipsGotSection::build() {
872872
if (tryMergeGots(MergedGots.front(), SrcGot, true)) {
873873
File->MipsGotIndex = 0;
874874
} else {
875-
if (!tryMergeGots(MergedGots.back(), SrcGot, false)) {
875+
// If this is the first time we failed to merge with the primary GOT,
876+
// MergedGots.back() will also be the primary GOT. We must make sure not
877+
// to try to merge again with IsPrimary=false, as otherwise, if the
878+
// inputs are just right, we could allow the primary GOT to become 1 or 2
879+
// words too big due to ignoring the header size.
880+
if (MergedGots.size() == 1 ||
881+
!tryMergeGots(MergedGots.back(), SrcGot, false)) {
876882
MergedGots.emplace_back();
877883
std::swap(MergedGots.back(), SrcGot);
878884
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.text
2+
.global foo1
3+
foo1:
4+
ld $2, %got_disp(local1)($gp)
5+
6+
.bss
7+
local1:
8+
.word 0

lld/test/ELF/hexagon.s

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
if (p0) jump:nt #_start
99
# CHECK: if (p0) jump:nt 0x11000
1010

11+
# R_HEX_B32_PCREL_X
12+
# R_HEX_B15_PCREL_X
13+
if (p0) jump:nt ##_start
14+
# CHECK: if (p0) jump:nt 0x11000
15+
1116
# R_HEX_B22_PCREL
1217
call #_start
1318
# CHECK: call 0x11000

lld/test/ELF/mips-64-got-overflow.s

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# REQUIRES: mips
2+
# Check the primary GOT cannot be made to overflow
3+
4+
# RUN: llvm-mc -filetype=obj -triple=mips64-unknown-linux \
5+
# RUN: %p/Inputs/mips-64-got-load.s -o %t1.so.o
6+
# RUN: llvm-mc -filetype=obj -triple=mips64-unknown-linux %s -o %t2.so.o
7+
# RUN: ld.lld -shared -mips-got-size 32 %t1.so.o %t2.so.o -o %t-sgot.so
8+
# RUN: ld.lld -shared -mips-got-size 24 %t1.so.o %t2.so.o -o %t-mgot.so
9+
# RUN: llvm-readobj -r -dt -mips-plt-got %t-sgot.so | FileCheck -check-prefix=SGOT %s
10+
# RUN: llvm-readobj -r -dt -mips-plt-got %t-mgot.so | FileCheck -check-prefix=MGOT %s
11+
12+
# SGOT: Primary GOT {
13+
# SGOT-NEXT: Canonical gp value: 0x27FF0
14+
# SGOT-NEXT: Reserved entries [
15+
# SGOT-NEXT: Entry {
16+
# SGOT-NEXT: Address:
17+
# SGOT-NEXT: Access: -32752
18+
# SGOT-NEXT: Initial: 0x0
19+
# SGOT-NEXT: Purpose: Lazy resolver
20+
# SGOT-NEXT: }
21+
# SGOT-NEXT: Entry {
22+
# SGOT-NEXT: Address:
23+
# SGOT-NEXT: Access: -32744
24+
# SGOT-NEXT: Initial: 0x80000000
25+
# SGOT-NEXT: Purpose: Module pointer (GNU extension)
26+
# SGOT-NEXT: }
27+
# SGOT-NEXT: ]
28+
# SGOT-NEXT: Local entries [
29+
# SGOT-NEXT: Entry {
30+
# SGOT-NEXT: Address:
31+
# SGOT-NEXT: Access: -32736
32+
# SGOT-NEXT: Initial: 0x20020
33+
# SGOT-NEXT: }
34+
# SGOT-NEXT: Entry {
35+
# SGOT-NEXT: Address:
36+
# SGOT-NEXT: Access: -32728
37+
# SGOT-NEXT: Initial: 0x20030
38+
# SGOT-NEXT: }
39+
# SGOT-NEXT: ]
40+
# SGOT-NEXT: Global entries [
41+
# SGOT-NEXT: ]
42+
# SGOT-NEXT: Number of TLS and multi-GOT entries: 0
43+
# SGOT-NEXT: }
44+
45+
# MGOT: Primary GOT {
46+
# MGOT-NEXT: Canonical gp value: 0x27FF0
47+
# MGOT-NEXT: Reserved entries [
48+
# MGOT-NEXT: Entry {
49+
# MGOT-NEXT: Address:
50+
# MGOT-NEXT: Access: -32752
51+
# MGOT-NEXT: Initial: 0x0
52+
# MGOT-NEXT: Purpose: Lazy resolver
53+
# MGOT-NEXT: }
54+
# MGOT-NEXT: Entry {
55+
# MGOT-NEXT: Address:
56+
# MGOT-NEXT: Access: -32744
57+
# MGOT-NEXT: Initial: 0x80000000
58+
# MGOT-NEXT: Purpose: Module pointer (GNU extension)
59+
# MGOT-NEXT: }
60+
# MGOT-NEXT: ]
61+
# MGOT-NEXT: Local entries [
62+
# MGOT-NEXT: Entry {
63+
# MGOT-NEXT: Address:
64+
# MGOT-NEXT: Access: -32736
65+
# MGOT-NEXT: Initial: 0x20020
66+
# MGOT-NEXT: }
67+
# MGOT-NEXT: ]
68+
# MGOT-NEXT: Global entries [
69+
# MGOT-NEXT: ]
70+
# MGOT-NEXT: Number of TLS and multi-GOT entries: 1
71+
# MGOT-NEXT: }
72+
73+
.text
74+
.global foo2
75+
foo2:
76+
ld $2, %got_disp(local2)($gp)
77+
78+
.bss
79+
local2:
80+
.word 0

lld/test/wasm/whole-archive.test

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
RUN: llc -filetype=obj %p/Inputs/start.ll -o %t.o
2+
RUN: llc -filetype=obj %p/Inputs/ret32.ll -o %t.ret32.o
3+
RUN: rm -f %t.a
4+
RUN: llvm-ar rcs %t.a %t.ret32.o
5+
6+
Should not add symbols from the archive by default as they are not required
7+
RUN: wasm-ld --no-gc-sections -o %t.wasm %t.o %t.a
8+
RUN: obj2yaml %t.wasm | FileCheck --check-prefix=NOTADDED %s
9+
NOTADDED: FunctionNames:
10+
NOTADDED-NOT: Name: ret32
11+
NOTADDED: ...
12+
13+
Should add symbols from the archive if --whole-archive is used
14+
RUN: wasm-ld --no-gc-sections -o %t.wasm %t.o --whole-archive %t.a
15+
RUN: obj2yaml %t.wasm | FileCheck --check-prefix=ADDED %s
16+
ADDED: FunctionNames:
17+
ADDED: Name: ret32
18+
ADDED: ...
19+
20+
--no-whole-archive should restore default behaviour
21+
RUN: wasm-ld --no-gc-sections -o %t.wasm %t.o --whole-archive --no-whole-archive %t.a
22+
RUN: obj2yaml %t.wasm | FileCheck --check-prefix=NOTADDED %s
23+
24+
--whole-archive and --no-whole-archive should affect only archives which follow them
25+
RUN: wasm-ld --no-gc-sections -o %t.wasm %t.o %t.a --whole-archive --no-whole-archive
26+
RUN: obj2yaml %t.wasm | FileCheck --check-prefix=NOTADDED %s
27+
RUN: wasm-ld --no-gc-sections -o %t.wasm %t.o --whole-archive %t.a --no-whole-archive
28+
RUN: obj2yaml %t.wasm | FileCheck --check-prefix=ADDED %s
29+
30+
--whole-archive should also work with thin archives
31+
RUN: rm -f %tthin.a
32+
RUN: llvm-ar --format=gnu rcsT %tthin.a %t.ret32.o
33+
RUN: wasm-ld --no-gc-sections -o %t.wasm %t.o --whole-archive %tthin.a
34+
RUN: obj2yaml %t.wasm | FileCheck --check-prefix=ADDED %s

lld/wasm/Driver.cpp

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ class LinkerDriver {
6868
void createFiles(opt::InputArgList &Args);
6969
void addFile(StringRef Path);
7070
void addLibrary(StringRef Name);
71+
72+
// True if we are in --whole-archive and --no-whole-archive.
73+
bool InWholeArchive = false;
74+
7175
std::vector<InputFile *> Files;
7276
};
7377
} // anonymous namespace
@@ -180,6 +184,37 @@ static void readImportFile(StringRef Filename) {
180184
Config->AllowUndefinedSymbols.insert(Sym);
181185
}
182186

187+
// Returns slices of MB by parsing MB as an archive file.
188+
// Each slice consists of a member file in the archive.
189+
std::vector<MemoryBufferRef> static getArchiveMembers(
190+
MemoryBufferRef MB) {
191+
std::unique_ptr<Archive> File =
192+
CHECK(Archive::create(MB),
193+
MB.getBufferIdentifier() + ": failed to parse archive");
194+
195+
std::vector<MemoryBufferRef> V;
196+
Error Err = Error::success();
197+
for (const ErrorOr<Archive::Child> &COrErr : File->children(Err)) {
198+
Archive::Child C =
199+
CHECK(COrErr, MB.getBufferIdentifier() +
200+
": could not get the child of the archive");
201+
MemoryBufferRef MBRef =
202+
CHECK(C.getMemoryBufferRef(),
203+
MB.getBufferIdentifier() +
204+
": could not get the buffer for a child of the archive");
205+
V.push_back(MBRef);
206+
}
207+
if (Err)
208+
fatal(MB.getBufferIdentifier() + ": Archive::children failed: " +
209+
toString(std::move(Err)));
210+
211+
// Take ownership of memory buffers created for members of thin archives.
212+
for (std::unique_ptr<MemoryBuffer> &MB : File->takeThinBuffers())
213+
make<std::unique_ptr<MemoryBuffer>>(std::move(MB));
214+
215+
return V;
216+
}
217+
183218
void LinkerDriver::addFile(StringRef Path) {
184219
Optional<MemoryBufferRef> Buffer = readFile(Path);
185220
if (!Buffer.hasValue())
@@ -188,6 +223,13 @@ void LinkerDriver::addFile(StringRef Path) {
188223

189224
switch (identify_magic(MBRef.getBuffer())) {
190225
case file_magic::archive: {
226+
// Handle -whole-archive.
227+
if (InWholeArchive) {
228+
for (MemoryBufferRef &M : getArchiveMembers(MBRef))
229+
Files.push_back(createObjectFile(M));
230+
return;
231+
}
232+
191233
SmallString<128> ImportFile = Path;
192234
path::replace_extension(ImportFile, ".imports");
193235
if (fs::exists(ImportFile))
@@ -197,10 +239,11 @@ void LinkerDriver::addFile(StringRef Path) {
197239
return;
198240
}
199241
case file_magic::bitcode:
200-
Files.push_back(make<BitcodeFile>(MBRef));
242+
case file_magic::wasm_object:
243+
Files.push_back(createObjectFile(MBRef));
201244
break;
202245
default:
203-
Files.push_back(make<ObjFile>(MBRef));
246+
error("unknown file type: " + MBRef.getBufferIdentifier());
204247
}
205248
}
206249

@@ -225,6 +268,12 @@ void LinkerDriver::createFiles(opt::InputArgList &Args) {
225268
case OPT_INPUT:
226269
addFile(Arg->getValue());
227270
break;
271+
case OPT_whole_archive:
272+
InWholeArchive = true;
273+
break;
274+
case OPT_no_whole_archive:
275+
InWholeArchive = false;
276+
break;
228277
}
229278
}
230279
}

lld/wasm/InputFiles.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,17 @@ Optional<MemoryBufferRef> lld::wasm::readFile(StringRef Path) {
4242
return MBRef;
4343
}
4444

45+
InputFile *lld::wasm::createObjectFile(MemoryBufferRef MB) {
46+
file_magic Magic = identify_magic(MB.getBuffer());
47+
if (Magic == file_magic::wasm_object)
48+
return make<ObjFile>(MB);
49+
50+
if (Magic == file_magic::bitcode)
51+
return make<BitcodeFile>(MB);
52+
53+
fatal("unknown file type: " + MB.getBufferIdentifier());
54+
}
55+
4556
void ObjFile::dumpInfo() const {
4657
log("info for: " + getName() +
4758
"\n Symbols : " + Twine(Symbols.size()) +
@@ -360,18 +371,7 @@ void ArchiveFile::addMember(const Archive::Symbol *Sym) {
360371
"could not get the buffer for the member defining symbol " +
361372
Sym->getName());
362373

363-
InputFile *Obj;
364-
365-
file_magic Magic = identify_magic(MB.getBuffer());
366-
if (Magic == file_magic::wasm_object) {
367-
Obj = make<ObjFile>(MB);
368-
} else if (Magic == file_magic::bitcode) {
369-
Obj = make<BitcodeFile>(MB);
370-
} else {
371-
error("unknown file type: " + MB.getBufferIdentifier());
372-
return;
373-
}
374-
374+
InputFile *Obj = createObjectFile(MB);
375375
Obj->ArchiveName = getName();
376376
Symtab->addFile(Obj);
377377
}

lld/wasm/InputFiles.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@ class BitcodeFile : public InputFile {
150150
std::unique_ptr<llvm::lto::InputFile> Obj;
151151
};
152152

153+
// Will report a fatal() error if the input buffer is not a valid bitcode
154+
// or was object file.
155+
InputFile *createObjectFile(MemoryBufferRef MB);
156+
153157
// Opens a given file.
154158
llvm::Optional<MemoryBufferRef> readFile(StringRef Path);
155159

lld/wasm/Options.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ def no_entry: F<"no-entry">,
132132
def stack_first: F<"stack-first">,
133133
HelpText<"Place stack at start of linear memory rather than after data">;
134134

135+
defm whole_archive: B<"whole-archive",
136+
"Force load of all members in a static library",
137+
"Do not force load of all members in a static library (default)">;
138+
135139
// Aliases
136140
def alias_entry_e: JoinedOrSeparate<["-"], "e">, Alias<entry>;
137141
def alias_entry_entry: J<"entry=">, Alias<entry>;

0 commit comments

Comments
 (0)