Hello everyone,
I am having some LD trouble, and I think I could use some help here, because I feel like I am fighting against the toolchain, instead of working with it.
My goal is to have the
.symtab and
.strtab sections of my kernel binary to be loaded into memory, so that I can consult them while the kernel is running. The obvious first attempt was to modify my linker script to include the following
SECTION entries:
Code:
.symtab :
{
sym_start = .; _sym_start = .; __sym_start = .;
*(.symtab)
sym_end = .; _sym_end = .; __sym_end = .;
}
.strtab :
{
str_start = .; _str_start = .; __str_start = .;
*(.strtab)
str_end = .; _str_end = .; __str_end = .;
}
This hopefully gathers the
.strtab and
.symtab sections of my individual object files into their respective sections in the final binary. Examining the final
.strtab seems to confirm my assumption.
However, when examining the sections of my final binary with
Code:
readelf -S
the aforementioned sections do not have any flags set, which means that they are not allocated or loadable and won't end up being loaded by GRUB (if I understand this correctly).
Also, the start and end symbols I have generated do not appear correct (start seems to equal end in all cases), as can be seen in the following screenshot.
https://imgur.com/bpS8FQrThe whole linker script is the following:
Code:
/* Kernel linker script */
ENTRY(start)
SECTIONS
{
.text 0x100000 :
{
code = .; _code = .; __code = .;
*(.text)
. = ALIGN(4096);
}
.data :
{
data = .; _data = .; __data = .;
*(.data)
*(.rodata)
. = ALIGN(4096);
}
.bss :
{
bss = .; _bss = .; __bss = .;
*(.bss)
. = ALIGN(4096);
}
.symtab :
{
sym_start = .; _sym_start = .; __sym_start = .;
*(.symtab)
sym_end = .; _sym_end = .; __sym_end = .;
}
.strtab :
{
str_start = .; _str_start = .; __str_start = .;
*(.strtab)
str_end = .; _str_end = .; __str_end = .;
}
end = .; _end = .; __end = .;
/DISCARD/ :
{
*(.eh_frame)
*(.note.gnu.build-id)
*(.comment)
}
}
CFLAGS are:
Code:
-nostdlib -nostdinc -fno-builtin -fno-stack-protector -std=c11 -I ./inc -D DEBUG -g
I also attempted to change the section flags with
objcopy, using
Code:
objcopy --set-section-flags .symtab=contents,alloc,load,readonly,data ./bin/kernel
which appears to have no effect.
Thank you in advance for your help!
Best regards,
Nick