| @@ -391,8 +391,9 @@ fn build_reports_the_time_of_each_phase() { |
| 391 | 391 | ); |
| 392 | 392 | } |
| 393 | 393 | |
| 394 | | −/// Release executables leave out the runtime's debug information, unless |
| 395 | | −/// the C flags ask for debug information (issue #115). |
| 394 | +/// Release executables leave out the runtime's debug information (issue |
| 395 | +/// #115) and the symbol table (ADR 0042), unless the C flags ask for debug |
| 396 | +/// information. |
| 396 | 397 | #[test] |
| 397 | 398 | fn release_builds_strip_the_runtime_debug_information() { |
| 398 | 399 | let lib = std::path::Path::new(env!("CARGO_BIN_EXE_louise")).with_file_name("liblouise_rt.a"); |
| @@ -401,10 +402,10 @@ fn release_builds_strip_the_runtime_debug_information() { |
| 401 | 402 | return; |
| 402 | 403 | } |
| 403 | 404 | let dir = std::path::PathBuf::from(env!("CARGO_TARGET_TMPDIR")).join("stripped"); |
| 404 | | − // Whether an ELF-64 executable has a `.debug_info` section: the names |
| 405 | | − // in its section-header string table (std holds the name as a string |
| 406 | | − // too, for its own backtraces, so the bytes alone don't tell). |
| 407 | | − let has_debug = |exe: &std::path::Path| { |
| 405 | + // Whether an ELF-64 executable has a section: the names in its |
| 406 | + // section-header string table (std holds `.debug_info` as a string too, |
| 407 | + // for its own backtraces, so the bytes alone don't tell). |
| 408 | + let has_section = |exe: &std::path::Path, section: &str| { |
| 408 | 409 | let b = std::fs::read(exe).unwrap(); |
| 409 | 410 | let u16_at = |o: usize| u16::from_le_bytes([b[o], b[o + 1]]) as usize; |
| 410 | 411 | let u32_at = |o: usize| u32::from_le_bytes(b[o..o + 4].try_into().unwrap()) as usize; |
| @@ -412,11 +413,13 @@ fn release_builds_strip_the_runtime_debug_information() { |
| 412 | 413 | let (shoff, shentsize, shnum, shstrndx) = |
| 413 | 414 | (u64_at(0x28), u16_at(0x3a), u16_at(0x3c), u16_at(0x3e)); |
| 414 | 415 | let strtab = u64_at(shoff + shstrndx * shentsize + 0x18); |
| 416 | + let wanted = format!("{section}\0"); |
| 415 | 417 | (0..shnum).any(|i| { |
| 416 | 418 | let name = strtab + u32_at(shoff + i * shentsize); |
| 417 | | − b[name..].starts_with(b".debug_info\0") |
| 419 | + b[name..].starts_with(wanted.as_bytes()) |
| 418 | 420 | }) |
| 419 | 421 | }; |
| 422 | + let has_debug = |exe: &std::path::Path| has_section(exe, ".debug_info"); |
| 420 | 423 | for (cflags, debug) in [("", false), ("-g", true)] { |
| 421 | 424 | let exe = dir.join(if debug { "with-g/hello" } else { "hello" }); |
| 422 | 425 | let out = Command::new(env!("CARGO_BIN_EXE_louise")) |
| @@ -432,6 +435,12 @@ fn release_builds_strip_the_runtime_debug_information() { |
| 432 | 435 | String::from_utf8_lossy(&out.stderr) |
| 433 | 436 | ); |
| 434 | 437 | assert_eq!(has_debug(&exe), debug, "LOUISE_CFLAGS={cflags:?}"); |
| 438 | + // Nor a symbol table (ADR 0042), unless asked for. |
| 439 | + assert_eq!( |
| 440 | + has_section(&exe, ".symtab"), |
| 441 | + debug, |
| 442 | + "LOUISE_CFLAGS={cflags:?}" |
| 443 | + ); |
| 435 | 444 | let run = Command::new(&exe).output().unwrap(); |
| 436 | 445 | assert_eq!(String::from_utf8_lossy(&run.stdout), "Hello, Louise!\n"); |
| 437 | 446 | } |
| @@ -449,14 +458,19 @@ fn unused_runtime_functions_are_left_out() { |
| 449 | 458 | } |
| 450 | 459 | let exe = std::path::PathBuf::from(env!("CARGO_TARGET_TMPDIR")).join("gc/hello"); |
| 451 | 460 | let _ = std::fs::remove_file(&exe); |
| 452 | | − let (ok, _, stderr) = louise(&[ |
| 453 | | − "build", |
| 454 | | − "--release", |
| 455 | | − "../../tests/run/hello.lse", |
| 456 | | − "-o", |
| 457 | | − exe.to_str().unwrap(), |
| 458 | | − ]); |
| 459 | | − assert!(ok, "{stderr}"); |
| 461 | + // Release builds strip the symbol table (ADR 0042); `-g` keeps it. |
| 462 | + let out = Command::new(env!("CARGO_BIN_EXE_louise")) |
| 463 | + .args(["build", "--release", "../../tests/run/hello.lse", "-o"]) |
| 464 | + .arg(&exe) |
| 465 | + .env("LOUISE_CFLAGS", "-g") |
| 466 | + .current_dir(env!("CARGO_MANIFEST_DIR")) |
| 467 | + .output() |
| 468 | + .unwrap(); |
| 469 | + assert!( |
| 470 | + out.status.success(), |
| 471 | + "{}", |
| 472 | + String::from_utf8_lossy(&out.stderr) |
| 473 | + ); |
| 460 | 474 | let symbols = Command::new("nm").arg(&exe).output().unwrap().stdout; |
| 461 | 475 | let symbols = String::from_utf8_lossy(&symbols); |
| 462 | 476 | assert!(symbols.contains("tl_main_program"), "the runtime is linked"); |
| @@ -561,6 +575,8 @@ fn program_functions_never_keep_the_thread_pointer() { |
| 561 | 575 | ]) |
| 562 | 576 | .arg(&exe) |
| 563 | 577 | .env("LOUISE_RUNTIME", "lto") |
| 578 | + // Keep the symbols (ADR 0042), which name the functions. |
| 579 | + .env("LOUISE_CFLAGS", "-g") |
| 564 | 580 | .current_dir(env!("CARGO_MANIFEST_DIR")) |
| 565 | 581 | .output() |
| 566 | 582 | .unwrap(); |