gbdev / gbdev/rgbds

Output smaller object files by omitting unnecessary symbols

Open
#2,017 3 comments 0 reactions 0 assignees View on GitHub
breaking enhancement rgbasm rgblink
Dominant language
C++
Stars
1.6k
Forks
193
Avg merge
22h 17m
Merged PRs (30d)
26

Description

Currently RGBASM's object file output contains all the symbols you define, even ones which have not been used nor exported. For example:

```console
$ cat foo.asm
def x = 1
def n equ 2
export def exp_c equ 3
def s equs "hello"

section "test", rom0
label: dw exp_label
exp_label:: dw label
$ rgbasm -o foo.o foo.asm
$ rgbobj -y name foo.o
foo.o [270 bytes]: RGBDS object v9 revision 13

Symbols
-------

exp_label
label
exp_c
x
n
s
```

This can result in very large object files, especially if the user has a habit of `INCLUDE`ing or `--preinclude`ing a comprehensive set of constant and macro definitions.

I believe it would be possible to mark each `Symbol` as `bool referenced` or not. We clearly know when symbols are referred to *before* they're defined, since we then create a `SYM_REF` for it, so the same detection should reliably work the rest of the time. (There's no way to refer to a symbol whose name is determined only at link time.) `EXPORT`ing a symbol would of course count as referring to it. Then the object output could just include the referenced symbols.

This would require an update to the object file format, since currently it declares a total number of symbols and then expects that many symbols to follow, and each symbol is internally referenced by its index in that sequence. Simply omitting symbols would break the indexing, so they'd need to each declare their own index/ID, or else have some kind of "skip" placeholder symbol which compactly acts like N unreferenced symbols at once.

This would also give more purpose to the `rgbasm -E/--export-all` flag. It originally existed because .sym and .map files would only list the exported symbols, so `-E` let the user have a more complete .sym file. But v0.5.0 changed them to always output all symbols (see #1916), leaving `-E` basically pointless. With this change, it would be a way to get all the symbols in the object file (whether or not there's any use to actually doing that).

Contributor guide

Open the contributing guide

Research direction

Start by tracing RGBASM's symbol handling and object-file output, then inspect rgbobj and the -E/--export-all behavior described in the issue. Review the object format's symbol-count and index assumptions before choosing a compatible representation. Done means unreferenced, unexported symbols are omitted by default, export-all retains them, and rgbobj can read the updated format.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.