Skip to content

Commit

Permalink
Auto merge of rust-lang#114048 - nikic:llvm-17, r=cuviper
Browse files Browse the repository at this point in the history
Update to LLVM 17

Expected LLVM 17.0.0 release date: Sep 5th
Rust 1.73 release date: Oct 5th

Compatibility changes in this PR:
 - Drop LLVM_RUSTLLVM check for target-cpu table, which no longer requires a patch with LLVM 17.
 - Update powerpc data layouts, which now include function alignment information. As usual, downgrade for older LLVM versions.
 - Adjust the stack-protector.rs test so that the stack smashing does not get optimized away.
 - Adjust path of crtbegin.c and crtend.c in compiler-rt.
 - Updated dist-riscv64-linux to use binutils 2.36 in order to recognize the zicsr feature, which is no longer part of the base ISA.
 - Fixed symlink for asm include directory on dist-various-2. We should use `/usr/include/x86_64-linux-gnu/asm` for the host, rather than `/usr/include/asm-generic`.

Upstream patches:
 - [x] https://reviews.llvm.org/D156525 (backported)

Perf run: https://perf.rust-lang.org/compare.html?start=f239bb6bea94d16d902c36d72b5cabdddefb3cab&end=8030d71a95a3ea79f5fc95232c32f9b78effb92d&stat=instructions:u

Fixes rust-lang#109671.

Successful: dist-x86_64-linux, dist-aarch64-linux, dist-s390x-linux, dist-powerpc-linux, armhf-gnu, wasm32
  • Loading branch information
bors committed Aug 7, 2023
2 parents 03a119b + 7867833 commit 443c316
Show file tree
Hide file tree
Showing 25 changed files with 38 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
[submodule "src/llvm-project"]
path = src/llvm-project
url = https://github.com/rust-lang/llvm-project.git
branch = rustc/16.0-2023-06-05
branch = rustc/17.0-2023-07-29
shallow = true
[submodule "src/doc/embedded-book"]
path = src/doc/embedded-book
Expand Down
11 changes: 11 additions & 0 deletions compiler/rustc_codegen_llvm/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,17 @@ pub unsafe fn create_module<'ll>(
target_data_layout = target_data_layout.replace("-n32:64-", "-n64-");
}
}
if llvm_version < (17, 0, 0) {
if sess.target.arch.starts_with("powerpc") {
// LLVM 17 specifies function pointer alignment for ppc:
// https://reviews.llvm.org/D147016
target_data_layout = target_data_layout
.replace("-Fn32", "")
.replace("-Fi32", "")
.replace("-Fn64", "")
.replace("-Fi64", "");
}
}

// Ensure the data-layout values hardcoded remain the defaults.
if sess.target.is_builtin {
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,6 @@ extern "C" void LLVMRustPrintTargetCPUs(LLVMTargetMachineRef TM,

#if LLVM_VERSION_GE(17, 0)
const ArrayRef<SubtargetSubTypeKV> CPUTable = MCInfo->getAllProcessorDescriptions();
#elif defined(LLVM_RUSTLLVM)
const ArrayRef<SubtargetSubTypeKV> CPUTable = MCInfo->getCPUTable();
#else
Buf << "Full target CPU help is not supported by this LLVM version.\n\n";
SubtargetSubTypeKV TargetCPUKV = { TargetCPU, {{}}, {{}} };
Expand Down Expand Up @@ -1120,7 +1118,7 @@ struct LLVMRustThinLTOData {

// Not 100% sure what these are, but they impact what's internalized and
// what's inlined across modules, I believe.
#if LLVM_VERSION_GE(17, 0)
#if LLVM_VERSION_GE(18, 0)
DenseMap<StringRef, FunctionImporter::ImportMapTy> ImportLists;
DenseMap<StringRef, FunctionImporter::ExportSetTy> ExportLists;
DenseMap<StringRef, GVSummaryMapTy> ModuleToDefinedGVSummaries;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_target/src/spec/powerpc64_ibm_aix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub fn target() -> Target {
Target {
llvm_target: "powerpc64-ibm-aix".into(),
pointer_width: 64,
data_layout: "E-m:a-i64:64-n32:64-S128-v256:256:256-v512:512:512".into(),
data_layout: "E-m:a-Fi64-i64:64-n32:64-S128-v256:256:256-v512:512:512".into(),
arch: "powerpc64".into(),
options: base,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub fn target() -> Target {
Target {
llvm_target: "powerpc64-unknown-freebsd".into(),
pointer_width: 64,
data_layout: "E-m:e-i64:64-n32:64".into(),
data_layout: "E-m:e-Fn32-i64:64-n32:64".into(),
arch: "powerpc64".into(),
options: TargetOptions { endian: Endian::Big, mcount: "_mcount".into(), ..base },
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub fn target() -> Target {
Target {
llvm_target: "powerpc64-unknown-linux-gnu".into(),
pointer_width: 64,
data_layout: "E-m:e-i64:64-n32:64-S128-v256:256:256-v512:512:512".into(),
data_layout: "E-m:e-Fi64-i64:64-n32:64-S128-v256:256:256-v512:512:512".into(),
arch: "powerpc64".into(),
options: TargetOptions { endian: Endian::Big, mcount: "_mcount".into(), ..base },
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub fn target() -> Target {
Target {
llvm_target: "powerpc64-unknown-linux-musl".into(),
pointer_width: 64,
data_layout: "E-m:e-i64:64-n32:64-S128-v256:256:256-v512:512:512".into(),
data_layout: "E-m:e-Fi64-i64:64-n32:64-S128-v256:256:256-v512:512:512".into(),
arch: "powerpc64".into(),
options: TargetOptions { endian: Endian::Big, mcount: "_mcount".into(), ..base },
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub fn target() -> Target {
Target {
llvm_target: "powerpc64-unknown-openbsd".into(),
pointer_width: 64,
data_layout: "E-m:e-i64:64-n32:64".into(),
data_layout: "E-m:e-Fn32-i64:64-n32:64".into(),
arch: "powerpc64".into(),
options: TargetOptions { endian: Endian::Big, mcount: "_mcount".into(), ..base },
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_target/src/spec/powerpc64_wrs_vxworks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub fn target() -> Target {
Target {
llvm_target: "powerpc64-unknown-linux-gnu".into(),
pointer_width: 64,
data_layout: "E-m:e-i64:64-n32:64-S128-v256:256:256-v512:512:512".into(),
data_layout: "E-m:e-Fi64-i64:64-n32:64-S128-v256:256:256-v512:512:512".into(),
arch: "powerpc64".into(),
options: TargetOptions { endian: Endian::Big, ..base },
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub fn target() -> Target {
Target {
llvm_target: "powerpc64le-unknown-freebsd".into(),
pointer_width: 64,
data_layout: "e-m:e-i64:64-n32:64".into(),
data_layout: "e-m:e-Fn32-i64:64-n32:64".into(),
arch: "powerpc64".into(),
options: TargetOptions { mcount: "_mcount".into(), ..base },
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub fn target() -> Target {
Target {
llvm_target: "powerpc64le-unknown-linux-gnu".into(),
pointer_width: 64,
data_layout: "e-m:e-i64:64-n32:64-S128-v256:256:256-v512:512:512".into(),
data_layout: "e-m:e-Fn32-i64:64-n32:64-S128-v256:256:256-v512:512:512".into(),
arch: "powerpc64".into(),
options: TargetOptions { mcount: "_mcount".into(), ..base },
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub fn target() -> Target {
Target {
llvm_target: "powerpc64le-unknown-linux-musl".into(),
pointer_width: 64,
data_layout: "e-m:e-i64:64-n32:64-S128-v256:256:256-v512:512:512".into(),
data_layout: "e-m:e-Fn32-i64:64-n32:64-S128-v256:256:256-v512:512:512".into(),
arch: "powerpc64".into(),
options: TargetOptions { mcount: "_mcount".into(), ..base },
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_target/src/spec/powerpc_unknown_freebsd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub fn target() -> Target {
Target {
llvm_target: "powerpc-unknown-freebsd13.0".into(),
pointer_width: 32,
data_layout: "E-m:e-p:32:32-i64:64-n32".into(),
data_layout: "E-m:e-p:32:32-Fn32-i64:64-n32".into(),
arch: "powerpc".into(),
options: TargetOptions {
endian: Endian::Big,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub fn target() -> Target {
Target {
llvm_target: "powerpc-unknown-linux-gnu".into(),
pointer_width: 32,
data_layout: "E-m:e-p:32:32-i64:64-n32".into(),
data_layout: "E-m:e-p:32:32-Fn32-i64:64-n32".into(),
arch: "powerpc".into(),
options: TargetOptions { endian: Endian::Big, mcount: "_mcount".into(), ..base },
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub fn target() -> Target {
Target {
llvm_target: "powerpc-unknown-linux-gnuspe".into(),
pointer_width: 32,
data_layout: "E-m:e-p:32:32-i64:64-n32".into(),
data_layout: "E-m:e-p:32:32-Fn32-i64:64-n32".into(),
arch: "powerpc".into(),
options: TargetOptions {
abi: "spe".into(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub fn target() -> Target {
Target {
llvm_target: "powerpc-unknown-linux-musl".into(),
pointer_width: 32,
data_layout: "E-m:e-p:32:32-i64:64-n32".into(),
data_layout: "E-m:e-p:32:32-Fn32-i64:64-n32".into(),
arch: "powerpc".into(),
options: TargetOptions { endian: Endian::Big, mcount: "_mcount".into(), ..base },
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_target/src/spec/powerpc_unknown_netbsd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub fn target() -> Target {
Target {
llvm_target: "powerpc-unknown-netbsd".into(),
pointer_width: 32,
data_layout: "E-m:e-p:32:32-i64:64-n32".into(),
data_layout: "E-m:e-p:32:32-Fn32-i64:64-n32".into(),
arch: "powerpc".into(),
options: TargetOptions { endian: Endian::Big, mcount: "__mcount".into(), ..base },
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_target/src/spec/powerpc_unknown_openbsd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub fn target() -> Target {
Target {
llvm_target: "powerpc-unknown-openbsd".into(),
pointer_width: 32,
data_layout: "E-m:e-p:32:32-i64:64-n32".into(),
data_layout: "E-m:e-p:32:32-Fn32-i64:64-n32".into(),
arch: "powerpc".into(),
options: base,
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_target/src/spec/powerpc_wrs_vxworks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub fn target() -> Target {
Target {
llvm_target: "powerpc-unknown-linux-gnu".into(),
pointer_width: 32,
data_layout: "E-m:e-p:32:32-i64:64-n32".into(),
data_layout: "E-m:e-p:32:32-Fn32-i64:64-n32".into(),
arch: "powerpc".into(),
options: TargetOptions { endian: Endian::Big, features: "+secure-plt".into(), ..base },
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_target/src/spec/powerpc_wrs_vxworks_spe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub fn target() -> Target {
Target {
llvm_target: "powerpc-unknown-linux-gnuspe".into(),
pointer_width: 32,
data_layout: "E-m:e-p:32:32-i64:64-n32".into(),
data_layout: "E-m:e-p:32:32-Fn32-i64:64-n32".into(),
arch: "powerpc".into(),
options: TargetOptions {
abi: "spe".into(),
Expand Down
4 changes: 2 additions & 2 deletions src/bootstrap/llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1159,8 +1159,8 @@ impl Step for CrtBeginEnd {
return out_dir;
}

let crtbegin_src = builder.src.join("src/llvm-project/compiler-rt/lib/crt/crtbegin.c");
let crtend_src = builder.src.join("src/llvm-project/compiler-rt/lib/crt/crtend.c");
let crtbegin_src = builder.src.join("src/llvm-project/compiler-rt/lib/builtins/crtbegin.c");
let crtend_src = builder.src.join("src/llvm-project/compiler-rt/lib/builtins/crtend.c");
if up_to_date(&crtbegin_src, &out_dir.join("crtbegin.o"))
&& up_to_date(&crtend_src, &out_dir.join("crtendS.o"))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ CT_ARCH_64=y
CT_ARCH_ARCH="rv64gc"
CT_KERNEL_LINUX=y
CT_LINUX_V_4_20=y
CT_BINUTILS_V_2_32=y
CT_BINUTILS_V_2_36=y
CT_GLIBC_V_2_29=y
CT_GCC_V_8=y
CT_CC_LANG_CXX=y
4 changes: 2 additions & 2 deletions src/ci/docker/host-x86_64/dist-various-2/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ ENV TARGETS=$TARGETS,x86_64-unknown-uefi
# As per https://bugs.launchpad.net/ubuntu/+source/gcc-defaults/+bug/1300211
# we need asm in the search path for gcc-9 (for gnux32) but not in the search path of the
# cross compilers.
# Luckily one of the folders is /usr/local/include so symlink /usr/include/asm-generic there
RUN ln -s /usr/include/asm-generic /usr/local/include/asm
# Luckily one of the folders is /usr/local/include so symlink /usr/include/x86_64-linux-gnu/asm there
RUN ln -s /usr/include/x86_64-linux-gnu/asm /usr/local/include/asm

ENV RUST_CONFIGURE_ARGS --enable-extended --enable-lld --disable-docs \
--set target.wasm32-wasi.wasi-root=/wasm32-wasi \
Expand Down
2 changes: 1 addition & 1 deletion src/llvm-project
2 changes: 2 additions & 0 deletions tests/ui/abi/stack-protector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ fn vulnerable_function() {
// Overwrite the on-stack return address with the address of `malicious_code()`,
// thereby jumping to that function when returning from `vulnerable_function()`.
unsafe { fill(stackaddr, bad_code_ptr, 20); }
// Capture the address, so the write is not optimized away.
std::hint::black_box(stackaddr);
}

// Use an uninlined function with its own stack frame to make sure that we don't
Expand Down

0 comments on commit 443c316

Please sign in to comment.