August 2, 2025

Sun 3 bootrom souce - Static symbols and underscores in global names

I like to declare function names "static" that are only used locally, i.e. in the same file in which they are declared. This provides a hint to me looking at code later. While it doesn't really matter here, it keeps such symbols out of the global namespace. It also means the symbol doesn't need to have its prototype added to the "protos.h" file.

I have been somewhat enthusiastic about doing this, and may find that some of these symbols actually are used in placed I didn't realized, but all that will get sorted out when I finally try to link all the files.

The underscore business

The sun C compiler added a "secret" underscore to the start of every global symbol name. So if you called a symbol "fish", at the assembly (and link) level, the symbol would be "_fish". There was probably some reason for this, perhaps avoiding clashes between function names and variable names.

The the more modern world of gcc, this is no longer done. This means that in the bootrom source code, a routine named "_restart" in assembly code will need to be renamed "restart". I am delaying fixing all this until I try to link all the files when all of this will become a glaring issue.

I will leave functions that are used only in assembly code with the underscore, if any such "local" functions exist.

Note that when assembly language code wants to make calls to code in C, I will need to trim an underscore where the call is made. Back in the sun day, the assembly language world saw all these underscores, but they were hidden in the C world. Of course calls from assembly code to assembly code could do whatever it wanted, it was the C compiler that added the hidden underscores.


Feedback? Questions? Drop me a line!

Tom's Computer Info / tom@mmto.org