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: Select all
.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 = .;
}
However, when examining the sections of my final binary with
Code: Select all
readelf -S
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/bpS8FQr
The whole linker script is the following:
Code: Select all
/* 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)
}
}
Code: Select all
-nostdlib -nostdinc -fno-builtin -fno-stack-protector -std=c11 -I ./inc -D DEBUG -g
Code: Select all
objcopy --set-section-flags .symtab=contents,alloc,load,readonly,data ./bin/kernel
Thank you in advance for your help!
Best regards,
Nick