Skip to content

Commit 66d7029

Browse files
committed
Merge branch 'master' into sync_from_rust_2026_03_13-2
2 parents f898471 + 552fc2f commit 66d7029

19 files changed

Lines changed: 547 additions & 294 deletions

.github/workflows/failures.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ jobs:
4848

4949
- name: Install libgccjit12
5050
if: matrix.libgccjit_version.gcc == 'libgccjit12.so'
51-
run: sudo apt-get install libgccjit-12-dev
51+
run: |
52+
sudo apt-get update
53+
sudo apt-get install libgccjit-12-dev
5254
5355
- name: Setup path to libgccjit
5456
if: matrix.libgccjit_version.gcc == 'libgccjit12.so'

.github/workflows/gcc12.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ jobs:
4646

4747
- name: Install packages
4848
# `llvm-14-tools` is needed to install the `FileCheck` binary which is used for asm tests.
49-
run: sudo apt-get install ninja-build ripgrep llvm-14-tools libgccjit-12-dev
49+
run: |
50+
sudo apt-get update
51+
sudo apt-get install ninja-build ripgrep llvm-14-tools libgccjit-12-dev
5052
5153
- name: Setup path to libgccjit
5254
run: echo 'gcc-path = "/usr/lib/gcc/x86_64-linux-gnu/12"' > config.toml

Cargo.toml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,8 @@ license = "MIT OR Apache-2.0"
99
crate-type = ["dylib"]
1010

1111
[[test]]
12-
name = "lang_tests_debug"
13-
path = "tests/lang_tests_debug.rs"
14-
harness = false
15-
[[test]]
16-
name = "lang_tests_release"
17-
path = "tests/lang_tests_release.rs"
12+
name = "lang_tests"
13+
path = "tests/lang_tests.rs"
1814
harness = false
1915

2016
[features]

example/mini_core_hello_world.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
)]
77
#![no_core]
88
#![allow(dead_code, internal_features, non_camel_case_types)]
9-
#![rustfmt_skip]
9+
#![cfg_attr(rustfmt, rustfmt_skip)]
1010

1111
extern crate mini_core;
1212

libgccjit.version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
efdd0a7290c22f5438d7c5380105d353ee3e8518
1+
2e6a09afb8d9ee9e190a81b0d7e3118251ebcb9a

src/archive.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
use std::path::Path;
2+
3+
use rustc_codegen_ssa::back::archive::{
4+
ArArchiveBuilder, ArchiveBuilder, ArchiveBuilderBuilder, DEFAULT_OBJECT_READER,
5+
};
6+
use rustc_session::Session;
7+
8+
pub(crate) struct ArArchiveBuilderBuilder;
9+
10+
impl ArchiveBuilderBuilder for ArArchiveBuilderBuilder {
11+
fn new_archive_builder<'a>(&self, sess: &'a Session) -> Box<dyn ArchiveBuilder + 'a> {
12+
Box::new(ArArchiveBuilder::new(sess, &DEFAULT_OBJECT_READER))
13+
}
14+
15+
fn create_dll_import_lib(
16+
&self,
17+
_sess: &Session,
18+
_lib_name: &str,
19+
_import_name_and_ordinal_vector: Vec<(String, Option<u16>)>,
20+
_output_path: &Path,
21+
) {
22+
unimplemented!("creating dll imports is not yet supported");
23+
}
24+
}

src/asm.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ use rustc_codegen_ssa::traits::{
1212
};
1313
use rustc_middle::bug;
1414
use rustc_middle::ty::Instance;
15-
use rustc_span::Span;
15+
use rustc_span::{DUMMY_SP, Span};
1616
use rustc_target::asm::*;
1717

1818
use crate::builder::Builder;
1919
use crate::callee::get_fn;
2020
use crate::context::CodegenCx;
21-
use crate::errors::UnwindingInlineAsm;
21+
use crate::errors::{NulBytesInAsm, UnwindingInlineAsm};
2222
use crate::type_of::LayoutGccExt;
2323

2424
// Rust asm! and GCC Extended Asm semantics differ substantially.
@@ -530,8 +530,15 @@ impl<'a, 'gcc, 'tcx> AsmBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
530530
template_str.push_str(INTEL_SYNTAX_INS);
531531
}
532532

533-
// 4. Generate Extended Asm block
533+
// NOTE: GCC's extended asm uses CString which cannot contain nul bytes.
534+
// Emit an error if there are any nul bytes in the template string.
535+
if template_str.contains('\0') {
536+
let err_sp = span.first().copied().unwrap_or(DUMMY_SP);
537+
self.sess().dcx().emit_err(NulBytesInAsm { span: err_sp });
538+
return;
539+
}
534540

541+
// 4. Generate Extended Asm block
535542
let block = self.llbb();
536543
let extended_asm = if let Some(dest) = dest {
537544
assert!(!labels.is_empty());
@@ -859,7 +866,7 @@ impl<'gcc, 'tcx> AsmCodegenMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
859866
template: &[InlineAsmTemplatePiece],
860867
operands: &[GlobalAsmOperandRef<'tcx>],
861868
options: InlineAsmOptions,
862-
_line_spans: &[Span],
869+
line_spans: &[Span],
863870
) {
864871
let asm_arch = self.tcx.sess.asm_arch.unwrap();
865872

@@ -926,6 +933,13 @@ impl<'gcc, 'tcx> AsmCodegenMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
926933
}
927934
// NOTE: seems like gcc will put the asm in the wrong section, so set it to .text manually.
928935
template_str.push_str("\n.popsection");
936+
// NOTE: GCC's add_top_level_asm uses CString which cannot contain nul bytes.
937+
// Emit an error if there are any nul bytes in the template string.
938+
if template_str.contains('\0') {
939+
let span = line_spans.first().copied().unwrap_or(DUMMY_SP);
940+
self.tcx.dcx().emit_err(NulBytesInAsm { span });
941+
return;
942+
}
929943
self.context.add_top_level_asm(None, &template_str);
930944
}
931945

src/errors.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,10 @@ pub(crate) struct LtoBitcodeFromRlib {
2323
#[derive(Diagnostic)]
2424
#[diag("explicit tail calls with the 'become' keyword are not implemented in the GCC backend")]
2525
pub(crate) struct ExplicitTailCallsUnsupported;
26+
27+
#[derive(Diagnostic)]
28+
#[diag("asm contains a NUL byte")]
29+
pub(crate) struct NulBytesInAsm {
30+
#[primary_span]
31+
pub span: Span,
32+
}

0 commit comments

Comments
 (0)