Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I am linking my own kernel with GNU ld and a simple script which says that OUTPUT_FORMAT should be a flat binary, and ENTRY point is the main function:

OUTPUT_FORMAT("binary")         /* flat file */
ENTRY("main")

So it is logical that the main function should be at the very beginning of the executable. But I noticed that the position of the object files in the resulting kernel file is the same as the way I specified them on the command line, so I must put main.o first. Is there any way to tell ld to put the file with the main() function at the beginning?

share|improve this question

closed as off topic by Gilles, Mat, Renan, Ulrich Dangel, jasonwryan Aug 21 '12 at 0:36

Questions on Unix & Linux Stack Exchange are expected to relate to Unix or Linux within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

1  
If you're compiling an ELF binary, the entry point is not the first byte of the executable file. Even if you're compiling to an executable format where the entry point is the first byte, the main function is not the entry point to the program, only to the C part; the entry point to the program is supplied by the compiler and calls main. –  Gilles Feb 25 '12 at 23:41
    
If you're writing your own kernel, the connection between your question and unix is tenuous at best. Unix & Linux doesn't handle development questions, except questions that are specifically about unix development tools. Your question belongs on Stack Overflow. Do not repost; I've requested that a moderator migrate your question there. –  Gilles Feb 25 '12 at 23:43
    
I agree, but this is question about gnu ld, which is part of every unix and linux dist. –  aleek Feb 25 '12 at 23:48
    
@aleek: by that reasoning, all programming questions that involve GCC would be on-topic here also. That's not the case. You have a programming question there, it's better off on Stack Overflow. –  Mat Feb 26 '12 at 10:05

Browse other questions tagged or ask your own question.