Skip to content

erl: use next_reloc for the paired symbol index, and stop dropping the last export - #925

Merged
uyjulian merged 1 commit into
ps2dev:masterfrom
rixnobis:erl/next-sym-and-export-drop
Sep 22, 2026
Merged

uyjulian merged 1 commit into
ps2dev:masterfrom
rixnobis:erl/next-sym-and-export-drop

Conversation

@rixnobis

Copy link
Copy Markdown
Contributor

Defects 1 and 2 from #924. Three lines, both verified at source on d317f8f0.

erl.c line 856 fetched next_reloc and then read reloc.r_info for the symbol index, so next_sym_n always equalled sym_n and the sec[sym[sym_n].st_shndx].sh_addr == sec[sym[next_sym_n].st_shndx].sh_addr term at line 883 was unconditionally true. The HI16/LO16 pairing guard did nothing.

build-exports.sh stored t[NR] and iterated i < NR in both loops, so the last symbol got neither a forward declaration nor an export_list[] entry.

Correcting one thing I said in #924 while I was here: I claimed the sort -n on line 6 makes every key compare as 0 so the order is the input order, and that the dropped symbol is therefore unstable. That is wrong. GNU sort falls back to a whole-line comparison when the keys tie, so sort -n on identifiers gives the same order as plain sort - printf 'zeta\nalpha\nmike\nbravo\n' | sort -n yields alpha bravo mike zeta, and only sort -n -s preserves input order. So the drop is deterministic: it is always the lexically last symbol. That makes the bug more findable rather than less, and I have left the sort -n alone here since it is not doing any harm.

Defects 3 and 4 are untouched. For 4 I have your ruling that the buildsystem name is the intended one and will follow it.

…e last export

erl.c line 856 read reloc.r_info instead of next_reloc.r_info, so next_sym_n
always equalled sym_n and the section-address comparison guarding HI16/LO16
pairing was unconditionally true.

build-exports.sh wrote t[NR] and then iterated i < NR twice, so whichever
symbol sorted last got neither a forward declaration nor an export_list[]
entry.

Reported in ps2dev#924.
@fjtrujy

fjtrujy commented Sep 22, 2026

Copy link
Copy Markdown
Member

@uyjulian ?

@uyjulian

Copy link
Copy Markdown
Member

Lgtm

@uyjulian
uyjulian merged commit 3304cd8 into ps2dev:master Sep 22, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants