LLBC-linker: do not strip debug symbols for nvptx

This was an issue for old ptx ISA versions. Those are not supported by rustc anymore
This commit is contained in:
Kjetil Kjeka
2026-05-02 21:36:35 +02:00
parent 67bcaa9c4b
commit 062ecd60a9
4 changed files with 37 additions and 11 deletions

View File

@@ -3,7 +3,7 @@ name = "llvm-bitcode-linker"
version = "0.0.1"
description = "A self-contained linker for llvm bitcode"
license = "MIT OR Apache-2.0"
edition = "2021"
edition = "2024"
publish = false
[dependencies]

View File

@@ -2,11 +2,10 @@ use std::path::PathBuf;
use anyhow::Context;
use crate::{Optimization, Target};
use crate::Optimization;
#[derive(Debug)]
pub struct Session {
target: Target,
cpu: Option<String>,
feature: Option<String>,
symbols: Vec<String>,
@@ -32,8 +31,9 @@ impl Session {
let opt_path = out_path.with_extension("optimized.o");
let sym_path = out_path.with_extension("symbols.txt");
tracing::debug!(%target, ?cpu, ?feature, ?out_path, "new session created");
Session {
target,
cpu,
feature,
symbols: Vec::new(),
@@ -86,15 +86,9 @@ impl Session {
/// Optimize and compile to native format using `opt` and `llc`
///
/// Before this can be called `link` needs to be called
fn optimize(&mut self, optimization: Optimization, mut debug: bool) -> anyhow::Result<()> {
fn optimize(&mut self, optimization: Optimization, debug: bool) -> anyhow::Result<()> {
let mut passes = format!("default<{}>", optimization);
// FIXME(@kjetilkjeka) Debug symbol generation is broken for nvptx64 so we must remove them even in debug mode
if debug && self.target == crate::Target::Nvptx64NvidiaCuda {
tracing::warn!("nvptx64 target detected - stripping debug symbols");
debug = false;
}
// We add an internalize pass as the rust compiler as we require exported symbols to be explicitly marked
passes.push_str(",internalize,globaldce");
let symbol_file_content = self.symbols.iter().fold(String::new(), |s, x| s + &x + "\n");

View File

@@ -18,3 +18,11 @@ impl std::str::FromStr for Target {
}
}
}
impl std::fmt::Display for Target {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Target::Nvptx64NvidiaCuda => f.write_str("nvptx64-nvidia-cuda"),
}
}
}

View File

@@ -0,0 +1,24 @@
//@ assembly-output: emit-asm
//@ compile-flags: --crate-type cdylib -C debuginfo=2
//@ only-nvptx64
// Tests related to debug symbols for nvptx
#![feature(abi_ptx)]
#![no_std]
//@ aux-build: breakpoint-panic-handler.rs
extern crate breakpoint_panic_handler;
#[no_mangle]
pub extern "ptx-kernel" fn foo() {
panic!("bar");
}
// We make sure that all debug sections are available and visit them
// CHECK: .section .debug_abbrev
// CHECK: .section .debug_info
// Issue #99248 describes a bug where `.` was used as a seperator
// instead of `_` for `anon`s in `.debug_info`
// CHECK-NOT: anon.