Re: How to compile a flat position-independent binary with G
Posted: Mon Nov 09, 2015 2:44 pm
Are you using a cross-compiler ?
The Place to Start for Operating System Developers
http://f.osdev.org/
No and I'm not about to switch to one as there has to be a simpler solution.gerryg400 wrote:Are you using a cross-compiler ?
It's a kernel and a number of userspace modules which have header information supplied elsewhere - they need to be flat binaries.gerryg400 wrote:I'm wondering whether you can compile each of your objects as an "ELF shared object" and load them into memory using dynamic loading ? To me that seems a simple and obvious solution unless I'm missing something in your requirements.
Code: Select all
beep.o: In function `output_char':
beep.c:(.text+0x34): undefined reference to `_GLOBAL_OFFSET_TABLE_'
Code: Select all
static void output_char(char character)
{
char uppercase_character;
if (character >= 'a' && character <= 'z')
{
uppercase_character = character - ('a' - 'A');
}
else
{
uppercase_character = character;
}
switch (uppercase_character)
{
case 'A':
output_seq("sl");
break;
case 'B':
output_seq("lsss");
break;
case 'C':
output_seq("lsls");
break;
<continued for remainder of alphabet and the digits 0 to 9>
case ' ':
pause();
pause();
pause();
pause();
pause();
break;
}
pause();
pause();
}
Code: Select all
beep.o: In function `start':
beep.c:(.text+0xe): undefined reference to `_GLOBAL_OFFSET_TABLE_'
Code: Select all
static void output_seq(char* seq)
{
uint8_t position;
position = 0;
while (seq[position] != 0)
{
switch (seq[position])
{
case 'l':
long_beep();
break;
case 's':
short_beep();
break;
}
position += 1;
}
}
Well, that's not entirely true....onlyonemac wrote:I'm asking what's wrong with my linker script/linking procedure, not whether I should use a cross-compiler and/or ELF-format binaries.
There's nothing wrong with the linker script per se, but your build script makes no sense. Could you please explain what it tries to do ?In the original post in this very thread you wrote:Just that, really. And do I need to build a cross-compiler for this ...
This link seems to explain it fairly well. A more detailed explanation can be found in chapters 5, 9, and 10 of Linkers and Loaders.The Global Offset Table redirects position independent address calculations to an absolute location and is located in the .got section of an ELF executable or shared object. It stores the final (absolute) location of a function call's symbol, used in dynamically linked code. When a program requests to use printf() for instance, after the rtld locates the symbol, the location is then relocated in the GOT and allows for the executable via the Procedure Linkage Table, to directly access the symbols location.
Calm down, output_seq is a static function in the same source code file as the calling function. In fact, all functions except the entry point are static at this stage and there are no global variables.Schol-R-LEA wrote:Long story short, you are calling output_seq() without an address for the function. If it is part of the kernel, then it shouldn't be a function call anyway, but a system call; otherwise, it should be linked into the program at compile time, in which case a flat binary (for the object file) simply isn't going to work. You might still be able to have the final linked executable stripped out into a flat binary, but as you can already see, using flat binaries is already becoming a problem for you, and I'm pretty sure it will only get worse over time. For something that is part of the OS, you probably can find a way to monkey this into a working setup; for user applications, probably not.
Yes I do have an executable format defined which is consistent with the format of many other areas of my operating system; using ELF would break this consistency and would thus be inappropriate. But I also think I should get some C code to compile *before* I start worrying about implementing a loader for *any* executable format.Schol-R-LEA wrote:Even if you don't use ELF, you will need some kind of format for the executables beyond a binary image. If you want to use a separate resource fork or other kind of external meta-data, fine, but if so you need to define it, in detail, before proceeding. No matter what you do, it will take at least as much work as implementing ELF will be, and you need to look at it carefully before proceeding and decide if your needs really are unique enough to justify developing a new executable format. It is possible they are, or that you will decide that the problem is interesting enough to go ahead with it anyway, but don't ever think that it will be the easier solution.
No, I refuse to use ELF just because you say so. Other people have used flat binaries and I will too. They have their place and their purpose, and their purpose is for those who want to write an operating system their own way. I don't care if ELF is easier, more standard, or whatever else. I have a plan for how I want to write my operating system and I will write it my way.iansjack wrote:Well, good luck.
I think you have been given enough information, and advice, as to how to solve your problem. Now it's up to you to use that information wisely.
I think your code is compiling. It seems to be failing at the linker step. I'm not sure whether you realise but gcc executes both the compiler and linker. It seems then that you are linking twice.onlyonemac wrote:No, I refuse to use ELF just because you say so. Other people have used flat binaries and I will too. They have their place and their purpose, and their purpose is for those who want to write an operating system their own way. I don't care if ELF is easier, more standard, or whatever else. I have a plan for how I want to write my operating system and I will write it my way.iansjack wrote:Well, good luck.
I think you have been given enough information, and advice, as to how to solve your problem. Now it's up to you to use that information wisely.
Now maybe someone else would like to help me with why my code won't compile WITHOUT first insisting that I must write my operating system their way rather than my own.