segfault when linking with ld
hi guys. i am having trouble using the linker ld. here is what i did:
Quote:
Quote:
Quote:
here is the program: Quote:
|
why not just let gcc do the linking
also why are you passing ld so many param's |
Quote:
btw, when i use ld and as to assemble and link assembly code, it works,; but i tried gcc -S to generate the assembly and then use as on the above program, but i got the same error. |
try a link without --dynamic-linker /lib/ld-linux.so.2
if still no go your libraries are broken and you need to replace them |
Quote:
Quote:
i don't think my libraries are broken, i got a fresh install from slackware 13.0. the only thing i did was recompile the kernel besides, this works fine: hello.s Quote:
Quote:
|
maybe gcc is broken in that case
|
Quote:
|
i tired it on windows without /lib/ld-linux.so.2
and got teste.exe stopped working in other words it crashed |
wait a minute
instead of -e main try -e _main |
Quote:
Quote:
|
Code:
ld --dynamic-linker /lib/ld-linux.so.2 /usr/lib/crt1.o /usr/lib/crti.o /usr/lib/crtn.o -lc teste.o -o teste |
I think carbonfiber gave you the right answer, but a little light on explanation.
In an ordinary C program, the main() function is not actually the entry point. Code runs before main to set up various aspects of the environment in which main runs, then it calls main. When main returns that code exits. The OP seems to be trying to make main be the entry point. The example seems to be simple enough (but I'm not sure) to run correctly without any of the work normally done before main(). But if main() is the entry point, rather than called by the startup routine, main() has nowhere to return to and cannot return. It could instead exit by calling exit(). In this example, I think exiting by calling exit() instead of returning would fix the problem. In other examples you might really need the startup code. The gcc -v suggested by carbonfiber gets gcc to show you the ld command it would use. If you want to invoke ld yourself but with the same results as having gcc invoke ld, you can copy important details (such as the startup module) from the command gcc would have used. |
hmmm i overlooked that meaning just dont use the -e switch
|
Quote:
|
All times are GMT -5. The time now is 09:19 AM. |