rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
98.23k stars 12.7k forks source link

LLVM ERROR: Misplaced debug info with -Cdebuginfo=1 -Zsanitizer=cfi -Clto #132615

Open 1c3t3a opened 7 hours ago

1c3t3a commented 7 hours ago

This is a repro of a bug that was observed in Chrome: https://b.corp.google.com/issues/40266913#comment46.

Code

Assume the following cross-language CFI setup

// src/main.rs

#![feature(str_from_raw_parts)]

use core::str;

extern "C" {
    fn hello();
}

extern "C" fn to_lowercase_rs(ptr: *const u8, len: usize) {
    let val = unsafe {
        str::from_raw_parts(ptr, len)
    };
    println!("{}", val.to_lowercase());
}

fn main() {
    unsafe {
        hello();
    }
}
// src/foo.cpp
extern "C" void to_lowercase_rs(char *ptr, int len);

extern "C" void hello() {
    char foo[] = "UPPER";
    to_lowercase_rs(foo, 4);
}
// build.rs
use cc::Build;

fn main() {
    println!("cargo::rerun-if-changed=src/foo.cpp");
    Build::new().compiler("clang").file("src/foo.cpp").compile("foo");
}

Meta

rustc --version --verbose:

rustc 1.84.0-nightly (b8c8287a2 2024-11-03)
binary: rustc
commit-hash: b8c8287a229cd79604aa84c25e1235fc78cd5f2e
commit-date: 2024-11-03
host: x86_64-unknown-linux-gnu
release: 1.84.0-nightly
LLVM version: 19.1.3

Error output

Executing: RUSTFLAGS="--cfg feature=\"panic_immediate_abort\" -Zsplit-lto-unit -Clinker-plugin-lto=yes -Coverflow-checks=on -Cdefault-linker-libraries -Zdep-info-omit-d-target -Zmacro-backtrace -Ccodegen-units=1 -Cpanic=abort -Zpanic_abort_tests -Copt-level=3 -Zdwarf-version=4 -Cdebuginfo=1 -Clinker-plugin-lto=yes -Zsanitizer=cfi -Zsanitizer-cfi-normalize-integers -Zsanitizer=cfi -Zsanitizer-cfi-normalize-integers" LDFLAGS="-Werror -fuse-ld=lld -Wl,--fatal-warnings -Wl,--build-id=fast -fPIC -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -Wl,--icf=all -Wl,--color-diagnostics -Wl,-mllvm,-instcombine-lower-dbg-declare=0 -Wl,-mllvm,-split-threshold-for-reg-with-hint=0 -Wl,--thinlto-cache-dir=thinlto-cache -Wl,--thinlto-cache-policy=cache_size=10\%:cache_size_bytes=40g:cache_size_files=100000 -flto=thin -Wl,--thinlto-jobs=all -Wl,-mllvm,-import-instr-limit=30 -Wl,-mllvm,-disable-auto-upgrade-debug-info -Wl,-mllvm,-inlinehint-threshold=360 -fwhole-program-vtables -Wl,--undefined-version -Wl,--no-call-graph-profile-sort -m64 -no-canonical-prefixes -Wl,--gc-sections -Wl,-z,defs -Wl,--as-needed -nostdlib++ -fsanitize=cfi-vcall -fsanitize=cfi-icall -fsanitize-cfi-icall-experimental-normalize-integers" cargo b -Z build-std=std,panic_abort --target x86_64-unknown-linux-gnu (this mirrors Chrome's RUSTFLAGS and LDFLAGS).

  = note: !dbg attachment points at wrong subprogram for function
          !2171 = distinct !DISubprogram(name: "find", linkageName: "_ZN6memchr6memmem9prefilter3x863sse4find17h2769ebfd75581b3cE", scope: !2173, file: !2172, line: 18, type: !15, scopeLine: 18, flags: DIFlagPrototyped, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: !8, templateParams: !16)
Backtrace

``` error: linking with `cc` failed: exit status: 1 | = note: LC_ALL="C" PATH="/usr/local/google/home/bkersting/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin:/usr/local/google/home/bkersting/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin/self-contained:/usr/local/google/home/bkersting/depot_tools:/usr/local/google/home/bkersting/.vscode-server/cli/servers/Stable-65edc4939843c90c34d61f4ce11704f09d3e5cb6/server/bin/remote-cli:/usr/local/google/home/bkersting/depot_tools:/usr/local/google/home/bkersting/.cargo/bin:/usr/lib/google-golang/bin:/usr/local/buildtools/java/jdk/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/google/home/bkersting/crosfleet:/usr/local/google/home/bkersting/arcanist/bin/:/usr/local/google/home/bkersting/.cargo/bin:/usr/local/google/home/bkersting/crosfleet:/usr/local/google/home/bkersting/arcanist/bin/:/usr/local/google/home/bkersting/.cargo/bin" VSLANG="1033" "cc" "-m64" "/tmp/rustcrPjQGi/symbols.o" "/usr/local/google/home/bkersting/rust_fuzz_test_domains/target/x86_64-unknown-linux-gnu/debug/deps/rust_fuzz_test_domains-bae0e739ee0d89d9.ajq76iu3hrg35qja6u1i4l2hr.rcgu.o" "/usr/local/google/home/bkersting/rust_fuzz_test_domains/target/x86_64-unknown-linux-gnu/debug/deps/rust_fuzz_test_domains-bae0e739ee0d89d9.80dwf0dsdrz6vvhafmsrrtrun.rcgu.o" "-Wl,--as-needed" "-Wl,-Bstatic" "-lfoo" "/usr/local/google/home/bkersting/rust_fuzz_test_domains/target/x86_64-unknown-linux-gnu/debug/deps/libstd-c9036c8f20139a25.rlib" "/usr/local/google/home/bkersting/rust_fuzz_test_domains/target/x86_64-unknown-linux-gnu/debug/deps/libpanic_abort-a6cb7ed4fcdc85bb.rlib" "/usr/local/google/home/bkersting/rust_fuzz_test_domains/target/x86_64-unknown-linux-gnu/debug/deps/libobject-bc4db1c993dbecb8.rlib" "/usr/local/google/home/bkersting/rust_fuzz_test_domains/target/x86_64-unknown-linux-gnu/debug/deps/libmemchr-27097fbf9312acb8.rlib" "/usr/local/google/home/bkersting/rust_fuzz_test_domains/target/x86_64-unknown-linux-gnu/debug/deps/libaddr2line-86cbc5d0ad57640d.rlib" "/usr/local/google/home/bkersting/rust_fuzz_test_domains/target/x86_64-unknown-linux-gnu/debug/deps/libgimli-895ebb30fd534b89.rlib" "/usr/local/google/home/bkersting/rust_fuzz_test_domains/target/x86_64-unknown-linux-gnu/debug/deps/librustc_demangle-d8b36f809296bc21.rlib" "/usr/local/google/home/bkersting/rust_fuzz_test_domains/target/x86_64-unknown-linux-gnu/debug/deps/libstd_detect-71c5f127ea5d2f1d.rlib" "/usr/local/google/home/bkersting/rust_fuzz_test_domains/target/x86_64-unknown-linux-gnu/debug/deps/libhashbrown-07413dadeba96242.rlib" "/usr/local/google/home/bkersting/rust_fuzz_test_domains/target/x86_64-unknown-linux-gnu/debug/deps/librustc_std_workspace_alloc-24427f34eab60c63.rlib" "/usr/local/google/home/bkersting/rust_fuzz_test_domains/target/x86_64-unknown-linux-gnu/debug/deps/libminiz_oxide-6959a588ccf75f09.rlib" "/usr/local/google/home/bkersting/rust_fuzz_test_domains/target/x86_64-unknown-linux-gnu/debug/deps/libadler-0ca6cd4ddbe2363f.rlib" "/usr/local/google/home/bkersting/rust_fuzz_test_domains/target/x86_64-unknown-linux-gnu/debug/deps/libunwind-44a9809ab9240785.rlib" "/usr/local/google/home/bkersting/rust_fuzz_test_domains/target/x86_64-unknown-linux-gnu/debug/deps/libcfg_if-45d704697ed21d16.rlib" "/usr/local/google/home/bkersting/rust_fuzz_test_domains/target/x86_64-unknown-linux-gnu/debug/deps/liblibc-91cdc09821427ae4.rlib" "/usr/local/google/home/bkersting/rust_fuzz_test_domains/target/x86_64-unknown-linux-gnu/debug/deps/liballoc-1bfe6209046a9a01.rlib" "/usr/local/google/home/bkersting/rust_fuzz_test_domains/target/x86_64-unknown-linux-gnu/debug/deps/librustc_std_workspace_core-e44df3f2e0ed8a40.rlib" "/usr/local/google/home/bkersting/rust_fuzz_test_domains/target/x86_64-unknown-linux-gnu/debug/deps/libcore-cae7c0618c2bb95f.rlib" "/usr/local/google/home/bkersting/rust_fuzz_test_domains/target/x86_64-unknown-linux-gnu/debug/deps/libcompiler_builtins-ec4512cba487e6af.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-B/usr/local/google/home/bkersting/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin/gcc-ld" "-fuse-ld=lld" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-Wl,-plugin-opt=O3,-plugin-opt=mcpu=x86-64" "-L" "/usr/local/google/home/bkersting/rust_fuzz_test_domains/target/x86_64-unknown-linux-gnu/debug/build/rust_fuzz_test_domains-34b0485ae16e7b3a/out" "-L" "/usr/local/google/home/bkersting/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "/usr/local/google/home/bkersting/rust_fuzz_test_domains/target/x86_64-unknown-linux-gnu/debug/deps/rust_fuzz_test_domains-bae0e739ee0d89d9" "-Wl,--gc-sections" "-pie" "-Wl,-z,relro,-z,now" "-Wl,-O1" = note: !dbg attachment points at wrong subprogram for function !2171 = distinct !DISubprogram(name: "find", linkageName: "_ZN6memchr6memmem9prefilter3x863sse4find17h2769ebfd75581b3cE", scope: !2173, file: !2172, line: 18, type: !15, scopeLine: 18, flags: DIFlagPrototyped, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: !8, templateParams: !16) ptr @_ZN6memchr6memmem9prefilter3x863sse4find17h2769ebfd75581b3cE.b6a156f9d44d59eb2e54da3a810f05fe %87 = icmp ult i64 %16, %5, !dbg !2378 !2378 = !DILocation(line: 107, column: 19, scope: !2379) !2379 = distinct !DILexicalBlock(scope: !2380, file: !2157, line: 106, column: 5) !2380 = distinct !DISubprogram(name: "simple_memchr_fallback", linkageName: "_ZN6memchr6memmem9prefilter22simple_memchr_fallback17h9eaa523324a439a0E", scope: !2142, file: !2157, line: 100, type: !15, scopeLine: 100, flags: DIFlagPrototyped, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: !8, templateParams: !16) rust-lld: warning: ignoring invalid debug info in /usr/local/google/home/bkersting/rust_fuzz_test_domains/target/x86_64-unknown-linux-gnu/debug/deps/libmemchr-27097fbf9312acb8.rlib(memchr-27097fbf9312acb8.memchr.57311dd4fc51d84d-cgu.0.rcgu.o at 787202) !dbg attachment points at wrong subprogram for function !2871 = distinct !DISubprogram(name: "to_lowercase", linkageName: "_ZN5alloc3str21_$LT$impl$u20$str$GT$12to_lowercase17h59325f8e863eccfdE", scope: !2872, file: !691, line: 384, type: !15, scopeLine: 384, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !8, templateParams: !16) ptr @"_ZN5alloc3str21_$LT$impl$u20$str$GT$12to_lowercase17h59325f8e863eccfdE" %110 = add i8 %87, -65, !dbg !185 !185 = !DILocation(line: 779, column: 25, scope: !186, inlinedAt: !187) !177 = distinct !DISubprogram(name: "to_ascii_lowercase", linkageName: "_ZN4core3num20_$LT$impl$u20$u8$GT$18to_ascii_lowercase17h60a1a19f3d9f1834E", scope: !179, file: !178, line: 630, type: !15, scopeLine: 630, flags: DIFlagPrototyped, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: !8, templateParams: !16) !177 = distinct !DISubprogram(name: "to_ascii_lowercase", linkageName: "_ZN4core3num20_$LT$impl$u20$u8$GT$18to_ascii_lowercase17h60a1a19f3d9f1834E", scope: !179, file: !178, line: 630, type: !15, scopeLine: 630, flags: DIFlagPrototyped, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: !8, templateParams: !16) rust-lld: warning: ignoring invalid debug info in /usr/local/google/home/bkersting/rust_fuzz_test_domains/target/x86_64-unknown-linux-gnu/debug/deps/liballoc-1bfe6209046a9a01.rlib(alloc-1bfe6209046a9a01.alloc.ff2cb029e740156c-cgu.0.rcgu.o at 6473000) inlinable function call in a function with debug info must have a !dbg location %104 = call noundef zeroext i1 @"_ZN68_$LT$core..fmt..builders..PadAdapter$u20$as$u20$core..fmt..Write$GT$9write_str17h9f1b051d8ddd1d34E"(ptr noundef nonnull align 1 %8, ptr noalias noundef nonnull readonly align 1 %1, i64 noundef %2) #44, !noalias !11726 inlinable function call in a function with debug info must have a !dbg location %106 = call noundef zeroext i1 @"_ZN68_$LT$core..fmt..builders..PadAdapter$u20$as$u20$core..fmt..Write$GT$9write_str17h9f1b051d8ddd1d34E"(ptr noundef nonnull align 1 %8, ptr noalias noundef nonnull readonly align 1 @anon.21ee6ffcae74f05773475a8da2bc14dd.88, i64 noundef 2) #44, !noalias !11731 inlinable function call in a function with debug info must have a !dbg location %49 = call noundef zeroext i1 @"_ZN68_$LT$core..fmt..builders..PadAdapter$u20$as$u20$core..fmt..Write$GT$9write_str17h9f1b051d8ddd1d34E"(ptr noundef nonnull align 1 %3, ptr noalias noundef nonnull readonly align 1 @anon.21ee6ffcae74f05773475a8da2bc14dd.93, i64 noundef 3) #44, !noalias !11826 inlinable function call in a function with debug info must have a !dbg location %49 = call noundef zeroext i1 @"_ZN68_$LT$core..fmt..builders..PadAdapter$u20$as$u20$core..fmt..Write$GT$9write_str17h9f1b051d8ddd1d34E"(ptr noundef nonnull align 1 %3, ptr noalias noundef nonnull readonly align 1 @anon.21ee6ffcae74f05773475a8da2bc14dd.93, i64 noundef 3) #44, !noalias !12075 inlinable function call in a function with debug info must have a !dbg location %49 = call noundef zeroext i1 @"_ZN68_$LT$core..fmt..builders..PadAdapter$u20$as$u20$core..fmt..Write$GT$9write_str17h9f1b051d8ddd1d34E"(ptr noundef nonnull align 1 %3, ptr noalias noundef nonnull readonly align 1 @anon.21ee6ffcae74f05773475a8da2bc14dd.93, i64 noundef 3) #44, !noalias !12337 inlinable function call in a function with debug info must have a !dbg location %49 = call noundef zeroext i1 @"_ZN68_$LT$core..fmt..builders..PadAdapter$u20$as$u20$core..fmt..Write$GT$9write_str17h9f1b051d8ddd1d34E"(ptr noundef nonnull align 1 %3, ptr noalias noundef nonnull readonly align 1 @anon.21ee6ffcae74f05773475a8da2bc14dd.93, i64 noundef 3) #44, !noalias !12568 inlinable function call in a function with debug info must have a !dbg location %54 = call noundef zeroext i1 @"_ZN68_$LT$core..fmt..builders..PadAdapter$u20$as$u20$core..fmt..Write$GT$9write_str17h9f1b051d8ddd1d34E"(ptr noundef nonnull align 1 %3, ptr noalias noundef nonnull readonly align 1 @anon.21ee6ffcae74f05773475a8da2bc14dd.93, i64 noundef 3) #44, !noalias !12932 rust-lld: warning: ignoring invalid debug info in /usr/local/google/home/bkersting/rust_fuzz_test_domains/target/x86_64-unknown-linux-gnu/debug/deps/libcore-cae7c0618c2bb95f.rlib(core-cae7c0618c2bb95f.core.362ed3097e9bb352-cgu.0.rcgu.o at 51494742) inlinable function call in a function with debug info must have a !dbg location call void @"_ZN3std3sys3pal4unix2fs8readlink28_$u7b$$u7b$closure$u7d$$u7d$17h5d6f2ee6bff94ed8E.c893384d28d65921702c8134620f25be"(ptr noalias nocapture noundef nonnull sret([24 x i8]) align 8 dereferenceable(24) %4, ptr align 1 poison, ptr noalias noundef nonnull readonly align 1 %17, i64 poison) #75, !noalias !54879 inlinable function call in a function with debug info must have a !dbg location call void @"_ZN104_$LT$std..sys_common..net..LookupHost$u20$as$u20$core..convert..TryFrom$LT$$LP$$RF$str$C$u16$RP$$GT$$GT$8try_from28_$u7b$$u7b$closure$u7d$$u7d$17hebe0611e4e1b7343E.c893384d28d65921702c8134620f25be"(ptr noalias nocapture noundef nonnull sret([32 x i8]) align 8 dereferenceable(32) %8, ptr noundef nonnull readonly align 1 %5, ptr noalias noundef nonnull readonly align 1 %55, i64 poison) #75, !noalias !72123 inlinable function call in a function with debug info must have a !dbg location tail call void @"_ZN104_$LT$std..sys_common..net..LookupHost$u20$as$u20$core..convert..TryFrom$LT$$LP$$RF$str$C$u16$RP$$GT$$GT$8try_from28_$u7b$$u7b$closure$u7d$$u7d$17hebe0611e4e1b7343E.c893384d28d65921702c8134620f25be"(ptr noalias nocapture noundef nonnull sret([32 x i8]) align 8 dereferenceable(32) %0, ptr noundef nonnull align 1 %3, ptr noalias noundef nonnull readonly align 1 %10, i64 poison) #75 inlinable function call in a function with debug info must have a !dbg location tail call void @"_ZN3std3sys3pal4unix2fs8readlink28_$u7b$$u7b$closure$u7d$$u7d$17h5d6f2ee6bff94ed8E.c893384d28d65921702c8134620f25be"(ptr noalias nocapture noundef nonnull sret([24 x i8]) align 8 dereferenceable(24) %0, ptr align 1 poison, ptr noalias noundef nonnull readonly align 1 %9, i64 poison) #75 inlinable function call in a function with debug info must have a !dbg location tail call void @"_ZN3std3sys3pal4unix2os6getenv28_$u7b$$u7b$closure$u7d$$u7d$17hb692136c4b4e12f4E.c893384d28d65921702c8134620f25be"(ptr noalias nocapture noundef nonnull sret([24 x i8]) align 8 dereferenceable(24) %0, ptr align 1 poison, ptr noalias noundef nonnull readonly align 1 %9, i64 poison) #75 inlinable function call in a function with debug info must have a !dbg location call void @"_ZN3std3sys3pal4unix2fs8readlink28_$u7b$$u7b$closure$u7d$$u7d$17h5d6f2ee6bff94ed8E.c893384d28d65921702c8134620f25be"(ptr noalias nocapture noundef nonnull sret([24 x i8]) align 8 dereferenceable(24) %7, ptr align 1 poison, ptr noalias noundef nonnull readonly align 1 %96, i64 poison) #75, !noalias !96665 inlinable function call in a function with debug info must have a !dbg location call void @"_ZN3std3sys3pal4unix2fs8readlink28_$u7b$$u7b$closure$u7d$$u7d$17h5d6f2ee6bff94ed8E.c893384d28d65921702c8134620f25be"(ptr noalias nocapture noundef nonnull sret([24 x i8]) align 8 dereferenceable(24) %0, ptr align 1 poison, ptr noalias noundef nonnull readonly align 1 %20, i64 poison) #75, !noalias !97356 inlinable function call in a function with debug info must have a !dbg location %22 = call noundef ptr @"_ZN3std3sys3pal4unix2os6setenv28_$u7b$$u7b$closure$u7d$$u7d$17hc72d9cefebc903f9E.c893384d28d65921702c8134620f25be"(ptr noundef nonnull align 1 %7, ptr noalias noundef nonnull readonly align 1 %21, i64 noundef %19) #75, !noalias !100704 inlinable function call in a function with debug info must have a !dbg location call void @"_ZN104_$LT$std..sys_common..net..LookupHost$u20$as$u20$core..convert..TryFrom$LT$$LP$$RF$str$C$u16$RP$$GT$$GT$8try_from28_$u7b$$u7b$closure$u7d$$u7d$17hebe0611e4e1b7343E.c893384d28d65921702c8134620f25be"(ptr noalias nocapture noundef nonnull sret([32 x i8]) align 8 dereferenceable(32) %0, ptr noundef nonnull readonly align 1 %6, ptr noalias noundef nonnull readonly align 1 %47, i64 poison) #75, !noalias !111844 inlinable function call in a function with debug info must have a !dbg location call void @"_ZN104_$LT$std..sys_common..net..LookupHost$u20$as$u20$core..convert..TryFrom$LT$$LP$$RF$str$C$u16$RP$$GT$$GT$8try_from28_$u7b$$u7b$closure$u7d$$u7d$17hebe0611e4e1b7343E.c893384d28d65921702c8134620f25be"(ptr noalias nocapture noundef nonnull sret([32 x i8]) align 8 dereferenceable(32) %0, ptr noundef nonnull readonly align 1 %5, ptr noalias noundef nonnull readonly align 1 %26, i64 poison) #75, !noalias !111883 rust-lld: warning: ignoring invalid debug info in /usr/local/google/home/bkersting/rust_fuzz_test_domains/target/x86_64-unknown-linux-gnu/debug/deps/libstd-c9036c8f20139a25.rlib(std-c9036c8f20139a25.std.f86d636ccb2240ff-cgu.0.rcgu.o at 8376952) rust-lld: error: undefined symbol: to_lowercase_rs >>> referenced by foo.cpp:5 (src/foo.cpp:5) >>> 2e40c9e35e9506f4-foo.o:(hello) in archive /usr/local/google/home/bkersting/rust_fuzz_test_domains/target/x86_64-unknown-linux-gnu/debug/build/rust_fuzz_test_domains-34b0485ae16e7b3a/out/libfoo.a collect2: error: ld returned 1 exit status warning: `rust_fuzz_test_domains` (bin "rust_fuzz_test_domains") generated 2 warnings error: could not compile `rust_fuzz_test_domains` (bin "rust_fuzz_test_domains") due to 1 previous error; 2 warnings emitted ```

rcvalle commented 7 hours ago

@rustbot claim