Skip to content

Discard .pdr in the PSP linker script - #161484

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
ItsNoHax:psp-discard-pdr
Aug 25, 2026
Merged

rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
ItsNoHax:psp-discard-pdr

Conversation

@ItsNoHax

Copy link
Copy Markdown
Contributor

The mipsel-sony-psp target passes --emit-relocs and relies on --gc-sections. .pdr (MIPS procedure-descriptor debug data) is not allocated, so it survives collection, but the relocations kept for it still point at the functions that were collected. rust-lld reports every one of those:

rust-lld: relocation refers to a discarded section: .text._RNvNtNtCs1mwba6qCgei_4libm4math3log3log
>>> referenced by libm-...-cgu.3.rcgu.o:(.rel.pdr+0xbfa0) in archive .../liblibm-....rlib

A hello-world picks up 70 of these. They were always emitted; they only became visible when cargo stopped suppressing linker output, and are now reported by the linker_messages lint. Reported downstream as overdrivenpotato/rust-psp#203.

Nothing on the PSP reads .pdr, so this discards it alongside the non-loadable sections the script already drops (.MIPS.abiflags, .reginfo). Discarding .pdr also removes .rel.pdr, since --emit-relocs only emits relocations for sections that survive.

Verification

Building rust-psp's ci/tests suite and running it on PPSSPP:

before after
discarded-section warnings 70 0
EBOOT.PBP size 1,395,948 B 1,264,396 B (−9.4%)
test suite 47 pass / 0 fail 47 pass / 0 fail (FINAL_SUCCESS)

Since the linker script lives in the target spec, I validated the exact change by building against a patched --print target-spec-json copy of the target, and cross-checked it by passing an equivalent /DISCARD/ fragment as an extra --script to a normal cargo psp build. Both give the same result.

This is the target's own linker script and affects no other target. The remaining warnings in that issue have a separate cause (EF_MIPS_CPIC) and are handled in a follow-up PR.

@rustbot

rustbot commented Aug 21, 2026

Copy link
Copy Markdown
Collaborator

These commits modify compiler targets.
(See the Target Tier Policy.)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 21, 2026
@rustbot

rustbot commented Aug 21, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome! The Rust Project has assigned @nnethercote (or someone else) to review your changes, you should hear from them (or someone else) within the next two weeks.

Please see the contribution instructions and our LLM policy for more information.

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 75 candidates
  • Random selection from 21 candidates

@ItsNoHax

Copy link
Copy Markdown
Contributor Author

@nnethercote This is LLM assisted, not able to edit the label. Considering the blast radius is small and the logic is solid I thought I'd go for it.

`.pdr` holds MIPS procedure-descriptor debug data. It is not allocated, so
`--gc-sections` does not collect it, but the relocations kept for it by the
target's `--emit-relocs` still refer to the functions that were collected.
rust-lld reports each of those as "relocation refers to a discarded section";
a hello-world picks up 70 such warnings, now that cargo no longer suppresses
linker output.

Nothing on the PSP reads `.pdr`, so discard it alongside the other non-loadable
sections already listed. This also drops ~9% off the resulting EBOOT.

Fixes overdrivenpotato/rust-psp#203 (in part)
@nnethercote

Copy link
Copy Markdown
Contributor

@ItsNoHax: can you clarify what you mean by "LLM assisted"? The policy permits certain LLM uses (e.g. analysis, review) and generally disallows others (e.g. creation).

@ItsNoHax

Copy link
Copy Markdown
Contributor Author

It was used for analysis @nnethercote.

@nnethercote

Copy link
Copy Markdown
Contributor

@bors r+ rollup

@rust-bors

rust-bors Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 8639b1f has been approved by nnethercote

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 25, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Aug 25, 2026
…rcote

Discard `.pdr` in the PSP linker script

The `mipsel-sony-psp` target passes `--emit-relocs` and relies on `--gc-sections`. `.pdr` (MIPS procedure-descriptor debug data) is not allocated, so it survives collection, but the relocations kept for it still point at the functions that *were* collected. rust-lld reports every one of those:

```
rust-lld: relocation refers to a discarded section: .text._RNvNtNtCs1mwba6qCgei_4libm4math3log3log
>>> referenced by libm-...-cgu.3.rcgu.o:(.rel.pdr+0xbfa0) in archive .../liblibm-....rlib
```

A hello-world picks up **70** of these. They were always emitted; they only became visible when cargo stopped suppressing linker output, and are now reported by the `linker_messages` lint. Reported downstream as overdrivenpotato/rust-psp#203.

Nothing on the PSP reads `.pdr`, so this discards it alongside the non-loadable sections the script already drops (`.MIPS.abiflags`, `.reginfo`). Discarding `.pdr` also removes `.rel.pdr`, since `--emit-relocs` only emits relocations for sections that survive.

### Verification

Building `rust-psp`'s `ci/tests` suite and running it on PPSSPP:

|                        | before      | after       |
| ---------------------- | ----------- | ----------- |
| discarded-section warnings | 70      | **0**       |
| `EBOOT.PBP` size       | 1,395,948 B | 1,264,396 B (−9.4%) |
| test suite             | 47 pass / 0 fail | 47 pass / 0 fail (`FINAL_SUCCESS`) |

Since the linker script lives in the target spec, I validated the exact change by building against a patched `--print target-spec-json` copy of the target, and cross-checked it by passing an equivalent `/DISCARD/` fragment as an extra `--script` to a normal `cargo psp` build. Both give the same result.

This is the target's own linker script and affects no other target. The remaining warnings in that issue have a separate cause (`EF_MIPS_CPIC`) and are handled in a follow-up PR.
rust-bors Bot pushed a commit that referenced this pull request Aug 25, 2026
Rollup of 5 pull requests

Successful merges:

 - #156749 (remove `box_patterns`)
 - #161411 (avoid overlapping const suggestions)
 - #161484 (Discard `.pdr` in the PSP linker script)
 - #161663 (Reduce dependency on implicit paths in bootstrap)
 - #161720 (rename rust_target_features query to make it clear that these are *all* target features)
@rust-bors
rust-bors Bot merged commit 968898a into rust-lang:main Aug 25, 2026
13 checks passed
@rustbot rustbot added this to the 1.100.0 milestone Aug 25, 2026
rust-bors Bot pushed a commit that referenced this pull request Aug 25, 2026
Rollup merge of #161484 - ItsNoHax:psp-discard-pdr, r=nnethercote

Discard `.pdr` in the PSP linker script

The `mipsel-sony-psp` target passes `--emit-relocs` and relies on `--gc-sections`. `.pdr` (MIPS procedure-descriptor debug data) is not allocated, so it survives collection, but the relocations kept for it still point at the functions that *were* collected. rust-lld reports every one of those:

```
rust-lld: relocation refers to a discarded section: .text._RNvNtNtCs1mwba6qCgei_4libm4math3log3log
>>> referenced by libm-...-cgu.3.rcgu.o:(.rel.pdr+0xbfa0) in archive .../liblibm-....rlib
```

A hello-world picks up **70** of these. They were always emitted; they only became visible when cargo stopped suppressing linker output, and are now reported by the `linker_messages` lint. Reported downstream as overdrivenpotato/rust-psp#203.

Nothing on the PSP reads `.pdr`, so this discards it alongside the non-loadable sections the script already drops (`.MIPS.abiflags`, `.reginfo`). Discarding `.pdr` also removes `.rel.pdr`, since `--emit-relocs` only emits relocations for sections that survive.

### Verification

Building `rust-psp`'s `ci/tests` suite and running it on PPSSPP:

|                        | before      | after       |
| ---------------------- | ----------- | ----------- |
| discarded-section warnings | 70      | **0**       |
| `EBOOT.PBP` size       | 1,395,948 B | 1,264,396 B (−9.4%) |
| test suite             | 47 pass / 0 fail | 47 pass / 0 fail (`FINAL_SUCCESS`) |

Since the linker script lives in the target spec, I validated the exact change by building against a patched `--print target-spec-json` copy of the target, and cross-checked it by passing an equivalent `/DISCARD/` fragment as an extra `--script` to a normal `cargo psp` build. Both give the same result.

This is the target's own linker script and affects no other target. The remaining warnings in that issue have a separate cause (`EF_MIPS_CPIC`) and are handled in a follow-up PR.
@ItsNoHax
ItsNoHax deleted the psp-discard-pdr branch August 25, 2026 13:52
pull Bot pushed a commit to LeeeeeeM/miri that referenced this pull request Aug 26, 2026
Rollup of 5 pull requests

Successful merges:

 - rust-lang/rust#156749 (remove `box_patterns`)
 - rust-lang/rust#161411 (avoid overlapping const suggestions)
 - rust-lang/rust#161484 (Discard `.pdr` in the PSP linker script)
 - rust-lang/rust#161663 (Reduce dependency on implicit paths in bootstrap)
 - rust-lang/rust#161720 (rename rust_target_features query to make it clear that these are *all* target features)
flip1995 pushed a commit to flip1995/rust-clippy that referenced this pull request Aug 28, 2026
Rollup of 5 pull requests

Successful merges:

 - rust-lang/rust#156749 (remove `box_patterns`)
 - rust-lang/rust#161411 (avoid overlapping const suggestions)
 - rust-lang/rust#161484 (Discard `.pdr` in the PSP linker script)
 - rust-lang/rust#161663 (Reduce dependency on implicit paths in bootstrap)
 - rust-lang/rust#161720 (rename rust_target_features query to make it clear that these are *all* target features)
vetleras pushed a commit to vetleras/rustfmt that referenced this pull request Aug 28, 2026
Rollup of 5 pull requests

Successful merges:

 - rust-lang/rust#156749 (remove `box_patterns`)
 - rust-lang/rust#161411 (avoid overlapping const suggestions)
 - rust-lang/rust#161484 (Discard `.pdr` in the PSP linker script)
 - rust-lang/rust#161663 (Reduce dependency on implicit paths in bootstrap)
 - rust-lang/rust#161720 (rename rust_target_features query to make it clear that these are *all* target features)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants