Skip to content

Commit febdd0b

Browse files
authored
Merge pull request #14 from emscripten-core/merge-19.1.6
Merge 19.1.6 into emscripten-libs-19
2 parents 1304b34 + 4c2a6ab commit febdd0b

File tree

72 files changed

+1309
-240
lines changed

Some content is hidden

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

72 files changed

+1309
-240
lines changed

clang/lib/Driver/ToolChains/Hexagon.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,10 @@ constructHexagonLinkArgs(Compilation &C, const JobAction &JA,
294294
bool IncStartFiles = !Args.hasArg(options::OPT_nostartfiles);
295295
bool IncDefLibs = !Args.hasArg(options::OPT_nodefaultlibs);
296296
bool UseG0 = false;
297-
const char *Exec = Args.MakeArgString(HTC.GetLinkerPath());
298-
bool UseLLD = (llvm::sys::path::filename(Exec).equals_insensitive("ld.lld") ||
299-
llvm::sys::path::stem(Exec).equals_insensitive("ld.lld"));
297+
bool UseLLD = false;
298+
const char *Exec = Args.MakeArgString(HTC.GetLinkerPath(&UseLLD));
299+
UseLLD = UseLLD || llvm::sys::path::filename(Exec).ends_with("ld.lld") ||
300+
llvm::sys::path::stem(Exec).ends_with("ld.lld");
300301
bool UseShared = IsShared && !IsStatic;
301302
StringRef CpuVer = toolchains::HexagonToolChain::GetTargetCPUVersion(Args);
302303

clang/lib/Interpreter/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ set(LLVM_LINK_COMPONENTS
1515
if (EMSCRIPTEN AND "lld" IN_LIST LLVM_ENABLE_PROJECTS)
1616
set(WASM_SRC Wasm.cpp)
1717
set(WASM_LINK lldWasm)
18+
set(COMMON_LINK lldCommon)
1819
endif()
1920

2021
add_clang_library(clangInterpreter
@@ -45,6 +46,7 @@ add_clang_library(clangInterpreter
4546
clangSema
4647
clangSerialization
4748
${WASM_LINK}
49+
${COMMON_LINK}
4850
)
4951

5052
if ((MINGW OR CYGWIN) AND BUILD_SHARED_LIBS)

clang/lib/Interpreter/IncrementalExecutor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class IncrementalExecutor {
5656
virtual llvm::Error addModule(PartialTranslationUnit &PTU);
5757
virtual llvm::Error removeModule(PartialTranslationUnit &PTU);
5858
virtual llvm::Error runCtors() const;
59-
llvm::Error cleanUp();
59+
virtual llvm::Error cleanUp();
6060
llvm::Expected<llvm::orc::ExecutorAddr>
6161
getSymbolAddress(llvm::StringRef Name, SymbolNameKind NameKind) const;
6262

clang/lib/Interpreter/Interpreter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,8 @@ IncrementalCompilerBuilder::CreateCpp() {
192192
#ifdef __EMSCRIPTEN__
193193
Argv.push_back("-target");
194194
Argv.push_back("wasm32-unknown-emscripten");
195-
Argv.push_back("-pie");
196195
Argv.push_back("-shared");
196+
Argv.push_back("-fvisibility=default");
197197
#endif
198198
Argv.insert(Argv.end(), UserArgs.begin(), UserArgs.end());
199199

clang/lib/Interpreter/Wasm.cpp

Lines changed: 50 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,31 @@
2323
#include <string>
2424

2525
namespace lld {
26+
enum Flavor {
27+
Invalid,
28+
Gnu, // -flavor gnu
29+
MinGW, // -flavor gnu MinGW
30+
WinLink, // -flavor link
31+
Darwin, // -flavor darwin
32+
Wasm, // -flavor wasm
33+
};
34+
35+
using Driver = bool (*)(llvm::ArrayRef<const char *>, llvm::raw_ostream &,
36+
llvm::raw_ostream &, bool, bool);
37+
38+
struct DriverDef {
39+
Flavor f;
40+
Driver d;
41+
};
42+
43+
struct Result {
44+
int retCode;
45+
bool canRunAgain;
46+
};
47+
48+
Result lldMain(llvm::ArrayRef<const char *> args, llvm::raw_ostream &stdoutOS,
49+
llvm::raw_ostream &stderrOS, llvm::ArrayRef<DriverDef> drivers);
50+
2651
namespace wasm {
2752
bool link(llvm::ArrayRef<const char *> args, llvm::raw_ostream &stdoutOS,
2853
llvm::raw_ostream &stderrOS, bool exitEarly, bool disableOutput);
@@ -51,13 +76,14 @@ llvm::Error WasmIncrementalExecutor::addModule(PartialTranslationUnit &PTU) {
5176
llvm::TargetMachine *TargetMachine = Target->createTargetMachine(
5277
PTU.TheModule->getTargetTriple(), "", "", TO, llvm::Reloc::Model::PIC_);
5378
PTU.TheModule->setDataLayout(TargetMachine->createDataLayout());
54-
std::string OutputFileName = PTU.TheModule->getName().str() + ".wasm";
79+
std::string ObjectFileName = PTU.TheModule->getName().str() + ".o";
80+
std::string BinaryFileName = PTU.TheModule->getName().str() + ".wasm";
5581

5682
std::error_code Error;
57-
llvm::raw_fd_ostream OutputFile(llvm::StringRef(OutputFileName), Error);
83+
llvm::raw_fd_ostream ObjectFileOutput(llvm::StringRef(ObjectFileName), Error);
5884

5985
llvm::legacy::PassManager PM;
60-
if (TargetMachine->addPassesToEmitFile(PM, OutputFile, nullptr,
86+
if (TargetMachine->addPassesToEmitFile(PM, ObjectFileOutput, nullptr,
6187
llvm::CodeGenFileType::ObjectFile)) {
6288
return llvm::make_error<llvm::StringError>(
6389
"Wasm backend cannot produce object.", llvm::inconvertibleErrorCode());
@@ -69,27 +95,30 @@ llvm::Error WasmIncrementalExecutor::addModule(PartialTranslationUnit &PTU) {
6995
llvm::inconvertibleErrorCode());
7096
}
7197

72-
OutputFile.close();
98+
ObjectFileOutput.close();
7399

74100
std::vector<const char *> LinkerArgs = {"wasm-ld",
75-
"-pie",
101+
"-shared",
76102
"--import-memory",
77-
"--no-entry",
78-
"--export-all",
79103
"--experimental-pic",
80-
"--no-export-dynamic",
81104
"--stack-first",
82-
OutputFileName.c_str(),
105+
"--allow-undefined",
106+
ObjectFileName.c_str(),
83107
"-o",
84-
OutputFileName.c_str()};
85-
int Result =
86-
lld::wasm::link(LinkerArgs, llvm::outs(), llvm::errs(), false, false);
87-
if (!Result)
108+
BinaryFileName.c_str()};
109+
110+
const lld::DriverDef WasmDriver = {lld::Flavor::Wasm, &lld::wasm::link};
111+
std::vector<lld::DriverDef> WasmDriverArgs;
112+
WasmDriverArgs.push_back(WasmDriver);
113+
lld::Result Result =
114+
lld::lldMain(LinkerArgs, llvm::outs(), llvm::errs(), WasmDriverArgs);
115+
116+
if (Result.retCode)
88117
return llvm::make_error<llvm::StringError>(
89118
"Failed to link incremental module", llvm::inconvertibleErrorCode());
90119

91120
void *LoadedLibModule =
92-
dlopen(OutputFileName.c_str(), RTLD_NOW | RTLD_GLOBAL);
121+
dlopen(BinaryFileName.c_str(), RTLD_NOW | RTLD_GLOBAL);
93122
if (LoadedLibModule == nullptr) {
94123
llvm::errs() << dlerror() << '\n';
95124
return llvm::make_error<llvm::StringError>(
@@ -109,6 +138,12 @@ llvm::Error WasmIncrementalExecutor::runCtors() const {
109138
return llvm::Error::success();
110139
}
111140

141+
llvm::Error WasmIncrementalExecutor::cleanUp() {
142+
// Can't call cleanUp through IncrementalExecutor as it
143+
// tries to deinitialize JIT which hasn't been initialized
144+
return llvm::Error::success();
145+
}
146+
112147
WasmIncrementalExecutor::~WasmIncrementalExecutor() = default;
113148

114-
} // namespace clang
149+
} // namespace clang

clang/lib/Interpreter/Wasm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class WasmIncrementalExecutor : public IncrementalExecutor {
2828
llvm::Error addModule(PartialTranslationUnit &PTU) override;
2929
llvm::Error removeModule(PartialTranslationUnit &PTU) override;
3030
llvm::Error runCtors() const override;
31+
llvm::Error cleanUp() override;
3132

3233
~WasmIncrementalExecutor() override;
3334
};

clang/utils/perf-training/perf-helper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def clean(args):
3636
+ "\tRemoves all files with extension from <path>."
3737
)
3838
return 1
39-
for path in args[1:-1]:
39+
for path in args[0:-1]:
4040
for filename in findFilesWithExtension(path, args[-1]):
4141
os.remove(filename)
4242
return 0

cmake/Modules/LLVMVersion.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ if(NOT DEFINED LLVM_VERSION_MINOR)
77
set(LLVM_VERSION_MINOR 1)
88
endif()
99
if(NOT DEFINED LLVM_VERSION_PATCH)
10-
set(LLVM_VERSION_PATCH 4)
10+
set(LLVM_VERSION_PATCH 6)
1111
endif()
1212
if(NOT DEFINED LLVM_VERSION_SUFFIX)
1313
set(LLVM_VERSION_SUFFIX)

compiler-rt/test/asan/TestCases/Windows/delay_dbghelp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// static build, there won't be any clang_rt DLLs.
1010
// RUN: not grep cl""ang_rt %t || \
1111
// RUN: grep cl""ang_rt %t | xargs which | \
12-
// RUN: xargs llvm-readobj --coff-imports | not grep dbghelp.dll %t
12+
// RUN: xargs llvm-readobj --coff-imports | not grep dbghelp.dll
1313

1414
extern "C" int puts(const char *);
1515

libcxx/include/__config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
// _LIBCPP_VERSION represents the version of libc++, which matches the version of LLVM.
2828
// Given a LLVM release LLVM XX.YY.ZZ (e.g. LLVM 17.0.1 == 17.00.01), _LIBCPP_VERSION is
2929
// defined to XXYYZZ.
30-
# define _LIBCPP_VERSION 190104
30+
# define _LIBCPP_VERSION 190106
3131

3232
# define _LIBCPP_CONCAT_IMPL(_X, _Y) _X##_Y
3333
# define _LIBCPP_CONCAT(_X, _Y) _LIBCPP_CONCAT_IMPL(_X, _Y)

lld/ELF/Arch/Hexagon.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ void Hexagon::relocate(uint8_t *loc, const Relocation &rel,
329329
case R_HEX_B22_PCREL:
330330
case R_HEX_GD_PLT_B22_PCREL:
331331
case R_HEX_PLT_B22_PCREL:
332-
checkInt(loc, val, 22, rel);
332+
checkInt(loc, val, 24, rel);
333333
or32le(loc, applyMask(0x1ff3ffe, val >> 2));
334334
break;
335335
case R_HEX_B22_PCREL_X:

lld/test/ELF/emulation-loongarch.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
# LA32-NEXT: StringTableSectionIndex:
3838
# LA32-NEXT: }
3939

40-
# RUN: llvm-mc -filetype=obj -triple=loongarch64 %s -o %t.o
40+
# RUN: llvm-mc -filetype=obj -triple=loongarch64 -mattr=+d %s -o %t.o
4141
# RUN: ld.lld %t.o -o %t
4242
# RUN: llvm-readobj --file-headers %t | FileCheck --check-prefix=LA64 %s
4343
# RUN: ld.lld -m elf64loongarch %t.o -o %t

lld/test/ELF/hexagon-jump-error.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ if (p0) jump #1f
2525
.section b15, "ax"
2626
1:
2727

28-
# CHECK: relocation R_HEX_B22_PCREL out of range: 8388612 is not in [-2097152, 2097151]
28+
# CHECK: relocation R_HEX_B22_PCREL out of range: 8388612 is not in [-8388608, 8388607]
2929
jump #1f
3030
.space (1<<23)
3131
.section b22, "ax"

lld/test/ELF/hexagon.s

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# REQUIRES: hexagon
22
# RUN: llvm-mc -filetype=obj -triple=hexagon-unknown-elf %s -o %t.o
33
# RUN: llvm-mc -filetype=obj -triple=hexagon-unknown-elf %S/Inputs/hexagon.s -o %t1.o
4-
# RUN: ld.lld %t.o %t1.o -o %t
4+
# RUN: ld.lld %t.o %t1.o -o %t --Ttext=0x200b4 --section-start=b_1000000=0x1000000 \
5+
# RUN: --section-start=b_1000400=0x1000400 --section-start=b_1004000=0x1004000 \
6+
# RUN: --section-start=b_1010000=0x1010000 --section-start=b_1800000=0x1800000
57
# RUN: llvm-objdump --no-print-imm-hex -d %t | FileCheck %s
68

79
# Note: 131584 == 0x20200
@@ -221,3 +223,40 @@ r0 = memw(r1+##_start)
221223

222224
memw(r0+##_start) = r1
223225
# CHECK: memw(r0+##131644) = r1
226+
227+
228+
## Tests for maximum branch ranges reachable without trampolines.
229+
230+
.section b_1000000, "ax"
231+
## The nop makes sure the first jump is within range.
232+
nop
233+
{ r0 = #0; jump #b_1000400 } // R_HEX_B9_PCREL
234+
if (r0==#0) jump:t #b_1004000 // R_HEX_B13_PCREL
235+
if (p0) jump #b_1010000 // R_HEX_B15_PCREL
236+
jump #b_1800000 // R_HEX_B22_PCREL
237+
238+
.section b_1000400, "ax"
239+
nop
240+
241+
.section b_1004000, "ax"
242+
nop
243+
244+
.section b_1010000, "ax"
245+
nop
246+
247+
.section b_1800000, "ax"
248+
nop
249+
250+
## Make sure we got the right relocations.
251+
# RUN: llvm-readelf -r %t.o | FileCheck %s --check-prefix=REL
252+
# REL: R_HEX_B9_PCREL 00000000 b_1000400
253+
# REL: R_HEX_B13_PCREL 00000000 b_1004000
254+
# REL: R_HEX_B15_PCREL 00000000 b_1010000
255+
# REL: R_HEX_B22_PCREL 00000000 b_1800000
256+
257+
# CHECK: 01000000 <b_1000000>:
258+
# CHECK-NEXT: 1000000: {{.*}} { nop }
259+
# CHECK-NEXT: 1000004: {{.*}} { r0 = #0 ; jump 0x1000400 }
260+
# CHECK-NEXT: 1000008: {{.*}} { if (r0==#0) jump:t 0x1004000 }
261+
# CHECK-NEXT: 100000c: {{.*}} { if (p0) jump:nt 0x1010000 }
262+
# CHECK-NEXT: 1000010: {{.*}} { jump 0x1800000 }

lld/test/ELF/loongarch-interlink.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33

44
# RUN: yaml2obj %t/blob.yaml -o %t/blob.o
55
# RUN: yaml2obj %t/v0-lp64d.yaml -o %t/v0-lp64d.o
6-
# RUN: llvm-mc --filetype=obj --triple=loongarch64-unknown-gnu %t/start.s -o %t/v1-lp64d.o
6+
# RUN: llvm-mc --filetype=obj --triple=loongarch64-unknown-gnu --mattr=+d %t/start.s -o %t/v1-lp64d.o
77
# RUN: llvm-mc --filetype=obj --triple=loongarch64-unknown-gnusf %t/start.s -o %t/v1-lp64s.o
8-
# RUN: llvm-mc --filetype=obj --triple=loongarch64-unknown-gnu %t/bar.s -o %t/v1-b-lp64d.o
8+
# RUN: llvm-mc --filetype=obj --triple=loongarch64-unknown-gnu --mattr=+d %t/bar.s -o %t/v1-b-lp64d.o
99

1010
## Check that binary input results in e_flags=0 output.
1111
# RUN: ld.lld -m elf64loongarch -b binary %t/blob.bin -o %t/blob.out

lld/wasm/SyntheticSections.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -587,8 +587,7 @@ void ElemSection::writeBody() {
587587
initExpr.Inst.Value.Global = WasmSym::tableBase->getGlobalIndex();
588588
} else {
589589
bool is64 = config->is64.value_or(false);
590-
initExpr.Inst.Opcode = is64 ? WASM_OPCODE_I64_CONST : WASM_OPCODE_I32_CONST;
591-
initExpr.Inst.Value.Int32 = config->tableBase;
590+
initExpr = intConst(config->tableBase, is64);
592591
}
593592
writeInitExpr(os, initExpr);
594593

llvm/include/llvm/Analysis/MemorySSAUpdater.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,11 @@ class MemorySSAUpdater {
192192
const BasicBlock *BB,
193193
MemorySSA::InsertionPlace Point);
194194

195+
MemoryAccess *createMemoryAccessInBB(Instruction *I, MemoryAccess *Definition,
196+
const BasicBlock *BB,
197+
MemorySSA::InsertionPlace Point,
198+
bool CreationMustSucceed);
199+
195200
/// Create a MemoryAccess in MemorySSA before an existing MemoryAccess.
196201
///
197202
/// See createMemoryAccessInBB() for usage details.

llvm/lib/Analysis/MemorySSAUpdater.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1404,8 +1404,17 @@ void MemorySSAUpdater::changeToUnreachable(const Instruction *I) {
14041404
MemoryAccess *MemorySSAUpdater::createMemoryAccessInBB(
14051405
Instruction *I, MemoryAccess *Definition, const BasicBlock *BB,
14061406
MemorySSA::InsertionPlace Point) {
1407-
MemoryUseOrDef *NewAccess = MSSA->createDefinedAccess(I, Definition);
1408-
MSSA->insertIntoListsForBlock(NewAccess, BB, Point);
1407+
return createMemoryAccessInBB(I, Definition, BB, Point,
1408+
/*CreationMustSucceed=*/true);
1409+
}
1410+
1411+
MemoryAccess *MemorySSAUpdater::createMemoryAccessInBB(
1412+
Instruction *I, MemoryAccess *Definition, const BasicBlock *BB,
1413+
MemorySSA::InsertionPlace Point, bool CreationMustSucceed) {
1414+
MemoryUseOrDef *NewAccess = MSSA->createDefinedAccess(
1415+
I, Definition, /*Template=*/nullptr, CreationMustSucceed);
1416+
if (NewAccess)
1417+
MSSA->insertIntoListsForBlock(NewAccess, BB, Point);
14091418
return NewAccess;
14101419
}
14111420

llvm/lib/Analysis/ScalarEvolution.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6313,8 +6313,10 @@ APInt ScalarEvolution::getConstantMultipleImpl(const SCEV *S) {
63136313
return getConstantMultiple(Z->getOperand()).zext(BitWidth);
63146314
}
63156315
case scSignExtend: {
6316+
// Only multiples that are a power of 2 will hold after sext.
63166317
const SCEVSignExtendExpr *E = cast<SCEVSignExtendExpr>(S);
6317-
return getConstantMultiple(E->getOperand()).sext(BitWidth);
6318+
uint32_t TZ = getMinTrailingZeros(E->getOperand());
6319+
return GetShiftedByZeros(TZ);
63186320
}
63196321
case scMulExpr: {
63206322
const SCEVMulExpr *M = cast<SCEVMulExpr>(S);

llvm/lib/CodeGen/MachineLICM.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1474,7 +1474,7 @@ void MachineLICMBase::InitializeLoadsHoistableLoops() {
14741474
if (!AllowedToHoistLoads[Loop])
14751475
continue;
14761476
for (auto &MI : *MBB) {
1477-
if (!MI.mayStore() && !MI.isCall() &&
1477+
if (!MI.isLoadFoldBarrier() && !MI.mayStore() && !MI.isCall() &&
14781478
!(MI.mayLoad() && MI.hasOrderedMemoryRef()))
14791479
continue;
14801480
for (MachineLoop *L = Loop; L != nullptr; L = L->getParentLoop())

0 commit comments

Comments
 (0)