Commit 022cd10
authored
Rollup merge of rust-lang#156950 - cezarbbb:staticlib-rename-internal-symbols, r=petrochenkov
Staticlib rename internal symbols
Follow-up to rust-lang#155338.
`-Zstaticlib-rename-internal-symbols` appends a crate-specific suffix (`_rs{StableCrateId}`) to non-exported symbols, resolving duplicate symbol conflicts when linking multiple Rust staticlibs into the same binary.
The implementation collects all defined `GLOBAL/WEAK` symbol names not in the exported set across all .o files, then renames them by extending the strtab and patching symbol name offsets. When combined with `-Zstaticlib-hide-internal-symbols`, the renamed symbols also receive `STV_HIDDEN` visibility.
Supported on ELF targets (Linux, BSD, etc.) and Apple targets (macOS, iOS, etc.). On unsupported targets (Windows), a warning is emitted and the flag has no effect.
r?@bjorn3 @petrochenkov17 files changed
Lines changed: 904 additions & 92 deletions
File tree
- compiler
- rustc_codegen_ssa/src
- back
- rustc_interface/src
- rustc_session/src
- src/doc/unstable-book/src/compiler-flags
- tests
- run-make
- staticlib-rename-internal-symbols-macho
- staticlib-rename-internal-symbols
- ui/linking
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
1 | 2 | | |
2 | 3 | | |
3 | 4 | | |
| |||
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
25 | | - | |
| 26 | + | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| |||
314 | 315 | | |
315 | 316 | | |
316 | 317 | | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
317 | 324 | | |
318 | 325 | | |
319 | 326 | | |
320 | 327 | | |
321 | 328 | | |
322 | | - | |
| 329 | + | |
323 | 330 | | |
324 | 331 | | |
325 | 332 | | |
| |||
534 | 541 | | |
535 | 542 | | |
536 | 543 | | |
537 | | - | |
| 544 | + | |
538 | 545 | | |
539 | | - | |
| 546 | + | |
540 | 547 | | |
541 | 548 | | |
542 | 549 | | |
| |||
546 | 553 | | |
547 | 554 | | |
548 | 555 | | |
549 | | - | |
550 | | - | |
551 | | - | |
552 | | - | |
553 | | - | |
| 556 | + | |
554 | 557 | | |
555 | 558 | | |
556 | 559 | | |
| |||
562 | 565 | | |
563 | 566 | | |
564 | 567 | | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
565 | 601 | | |
566 | 602 | | |
567 | 603 | | |
| |||
588 | 624 | | |
589 | 625 | | |
590 | 626 | | |
591 | | - | |
| 627 | + | |
592 | 628 | | |
593 | | - | |
| 629 | + | |
594 | 630 | | |
595 | 631 | | |
596 | 632 | | |
| |||
602 | 638 | | |
603 | 639 | | |
604 | 640 | | |
605 | | - | |
| 641 | + | |
606 | 642 | | |
607 | | - | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
608 | 648 | | |
609 | 649 | | |
610 | 650 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
56 | | - | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
57 | 59 | | |
58 | 60 | | |
59 | 61 | | |
| |||
566 | 568 | | |
567 | 569 | | |
568 | 570 | | |
569 | | - | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
570 | 575 | | |
571 | | - | |
572 | | - | |
573 | | - | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
574 | 586 | | |
575 | 587 | | |
576 | 588 | | |
| |||
581 | 593 | | |
582 | 594 | | |
583 | 595 | | |
584 | | - | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
585 | 604 | | |
586 | 605 | | |
587 | 606 | | |
| |||
0 commit comments