Discussion:
start-up object files
LHB
2011-10-26 23:42:52 UTC
Permalink
I managed to compile musl libc with pcc. I am wondering about startup
files. musl comes with its own startup object files, so which are the
correct ones? If anyone is feeling generous they might add the purpose
of these files. What good are they?

Thanks ahead.
--
LHB Jr.
Iain Hibbert
2011-10-27 08:48:39 UTC
Permalink
Post by LHB
I managed to compile musl libc with pcc. I am wondering about startup
files. musl comes with its own startup object files, so which are the
correct ones?
It will be a combination, since there may be features provided in either
which are required either by the musl libc code, or the pcc generated code
Post by LHB
If anyone is feeling generous they might add the purpose of these files.
What good are they?
they are the code that is run before main() is called and after it returns
or exit() is called, they set up the environment that C code expects (some
of this may be required by the library code, some of it by the compiler
and some by the host :)

for instance..

A musl library function may use a getenv() call to check the runtime
environment (eg malloc sometimes does this) and the musl libc getenv()
function might require a __musl_env pointer to be pre-initialized. The
musl startup could would handle that.

A pcc compiled function in application code may be marked with "#pragma
init" which means that pcc puts the address into an array in a special
section so that the code will be run before main() is called. The pcc
startup code would handle this.

Then, there can be target (both OS & machine) dependencies in the startup
code for processes, exactly how it receives information, exactly how it
must terminate. The host startup code would handle that.

You will probably find though, that if musl libc was designed to be built
by gcc on your system, that the gcc-compat in pcc is enough to let the
musl libc startup code work fine, and you might find also that the pcc
startup code would also work just great.. However, it could be worth
checking to see exactly what the startup code does to verify that there
will be no problems if you want to use it in a production item :)

iain
LHB
2011-10-27 18:45:37 UTC
Permalink
Post by Iain Hibbert
Post by LHB
I managed to compile musl libc with pcc. I am wondering about startup
files. musl comes with its own startup object files, so which are the
correct ones?
It will be a combination, since there may be features provided in either
which are required either by the musl libc code, or the pcc generated code
Thank yoy for this answer. Not the unrealistically simple
straightforward answer I was hoping for, but then again a simple answer
wouldn't be as much fun. musl doesn't seem to use builtins (except one
macro guarded one) so I'm hoping I can build a complete binutils, musl,
pcc toolchain with it.

BTW: I found it amusing that compiling musl choked on gcc (because of
ubuntu) but compiled without a hiccup with pcc.

Thanks!
LHB
Post by Iain Hibbert
Post by LHB
If anyone is feeling generous they might add the purpose of these files.
What good are they?
they are the code that is run before main() is called and after it returns
or exit() is called, they set up the environment that C code expects (some
of this may be required by the library code, some of it by the compiler
and some by the host :)
for instance..
A musl library function may use a getenv() call to check the runtime
environment (eg malloc sometimes does this) and the musl libc getenv()
function might require a __musl_env pointer to be pre-initialized. The
musl startup could would handle that.
A pcc compiled function in application code may be marked with "#pragma
init" which means that pcc puts the address into an array in a special
section so that the code will be run before main() is called. The pcc
startup code would handle this.
Then, there can be target (both OS& machine) dependencies in the startup
code for processes, exactly how it receives information, exactly how it
must terminate. The host startup code would handle that.
You will probably find though, that if musl libc was designed to be built
by gcc on your system, that the gcc-compat in pcc is enough to let the
musl libc startup code work fine, and you might find also that the pcc
startup code would also work just great.. However, it could be worth
checking to see exactly what the startup code does to verify that there
will be no problems if you want to use it in a production item :)
iain
--
LHB Jr.
Loading...