ELF question
ELF question
Should I load into the memory something more than the segments that are specified in program header? I don't use paging for now, ELFs can corrupt my memory, but I just want to make them execute normally and not trigger GPF when anything such as the variables or functions are used. So should I load something more than the program segments?
P.S. This post definitely has grammar mistakes. I should work on my English...
P.S. This post definitely has grammar mistakes. I should work on my English...
Developing U365.
Source:
only testing: http://gitlab.com/bps-projs/U365/tree/testing
OSDev newbies can copy any code from my repositories, just leave a notice that this code was written by U365 development team, not by you.
Source:
only testing: http://gitlab.com/bps-projs/U365/tree/testing
OSDev newbies can copy any code from my repositories, just leave a notice that this code was written by U365 development team, not by you.
Re: ELF question
If the ELF file is an executable without PT_INTERP and PT_DYNAMIC it is enough to just load the program headers. If it has a PT_INTERP/PT_DYNAMIC segment you need a dynamic linker that fixes the GOT, performs load-time relocations and calls library initialization functions.
Note that you need a different linker script for each executable if you do not use paging which is quite ugly and inflexible.
Note that you need a different linker script for each executable if you do not use paging which is quite ugly and inflexible.
managarm: Microkernel-based OS capable of running a Wayland desktop (Discord: https://discord.gg/7WB6Ur3). My OS-dev projects: [mlibc: Portable C library for managarm, qword, Linux, Sigma, ...] [LAI: AML interpreter] [xbstrap: Build system for OS distributions].
Re: ELF question
Yes. You should load all segments marked as PT_LOAD (so not all program headers), and also don't forget about bss. You don't have to load it from the file, but you'll have to allocate memory for it and fill it with zeros.
Other than that I agree with Korona, you should first implement paging (it can be a headache at first glance, but later on it will pay out!)
Other than that I agree with Korona, you should first implement paging (it can be a headache at first glance, but later on it will pay out!)
Re: ELF question
if you need to load elfs before paging, why not. Beware of two little things:
- Be sure you won't override used/non free physical ram. Yes, grub doesn't that. you can load your kernel at 0xB8000 and literally see what happens.
- When you activate paging, relocations you have you did before will be broken. I don't suggest you running your elf code after .
- Be sure you won't override used/non free physical ram. Yes, grub doesn't that. you can load your kernel at 0xB8000 and literally see what happens.
- When you activate paging, relocations you have you did before will be broken. I don't suggest you running your elf code after .
- xenos
- Member
- Posts: 1121
- Joined: Thu Aug 11, 2005 11:00 pm
- Libera.chat IRC: xenos1984
- Location: Tartu, Estonia
- Contact:
Re: ELF question
Does GRUB really load anything under the 1MB barrier? I thought it would throw some error in that case. I haven't tried it, though.Boris wrote:Yes, grub doesn't that. you can load your kernel at 0xB8000 and literally see what happens.
- Schol-R-LEA
- Member
- Posts: 1925
- Joined: Fri Oct 27, 2006 9:42 am
- Location: Athens, GA, USA
Re: ELF question
For that matter, don't forget that the .data and .rodata sections are 'program' as well, in addition to the .text and .bss sections. I am assuming you are loading those, but a reminder doesn't hurt.bzt wrote:don't forget about bss. You don't have to load it from the file, but you'll have to allocate memory for it and fill it with zeros.
Needless to say, you don't need to load .comment and .note sections, and you only need to work with .stab and .stabstr for debugging or other things that need to map the symbols to the addresses at runtime. Whether you use the .eh_frame, if any, will depend on how your OS handles unwinding the stack under certain conditions, but unless you are running a profiler or your OS swizzles userland stacks for some other purposes, you probably don't need to load it either.
Rev. First Speaker Schol-R-LEA;2 LCF ELF JAM POEE KoR KCO PPWMTF
Ordo OS Project
Lisp programmers tend to seem very odd to outsiders, just like anyone else who has had a religious experience they can't quite explain to others.
Ordo OS Project
Lisp programmers tend to seem very odd to outsiders, just like anyone else who has had a religious experience they can't quite explain to others.
Re: ELF question
Ha, true . It was not grub, but it was multiboot of qemu !XenOS wrote:Does GRUB really load anything under the 1MB barrier? I thought it would throw some error in that case. I haven't tried it, though.Boris wrote:Yes, grub doesn't that. you can load your kernel at 0xB8000 and literally see what happens.
Re: ELF question
Thanks. I will try to fix itSchol-R-LEA wrote:For that matter, don't forget that the .data and .rodata sections are 'program' as well, in addition to the .text and .bss sections. I am assuming you are loading those, but a reminder doesn't hurt.bzt wrote:don't forget about bss. You don't have to load it from the file, but you'll have to allocate memory for it and fill it with zeros.
Needless to say, you don't need to load .comment and .note sections, and you only need to work with .stab and .stabstr for debugging or other things that need to map the symbols to the addresses at runtime. Whether you use the .eh_frame, if any, will depend on how your OS handles unwinding the stack under certain conditions, but unless you are running a profiler or your OS swizzles userland stacks for some other purposes, you probably don't need to load it either.
Developing U365.
Source:
only testing: http://gitlab.com/bps-projs/U365/tree/testing
OSDev newbies can copy any code from my repositories, just leave a notice that this code was written by U365 development team, not by you.
Source:
only testing: http://gitlab.com/bps-projs/U365/tree/testing
OSDev newbies can copy any code from my repositories, just leave a notice that this code was written by U365 development team, not by you.
Re: ELF question
I know that I should load only PT_LOAD ones.bzt wrote:Yes. You should load all segments marked as PT_LOAD (so not all program headers), and also don't forget about bss. You don't have to load it from the file, but you'll have to allocate memory for it and fill it with zeros.
Other than that I agree with Korona, you should first implement paging (it can be a headache at first glance, but later on it will pay out!)
Developing U365.
Source:
only testing: http://gitlab.com/bps-projs/U365/tree/testing
OSDev newbies can copy any code from my repositories, just leave a notice that this code was written by U365 development team, not by you.
Source:
only testing: http://gitlab.com/bps-projs/U365/tree/testing
OSDev newbies can copy any code from my repositories, just leave a notice that this code was written by U365 development team, not by you.
Re: ELF question
How do you get grub2 to do this? I am assuming you mean it rather than legacy. Can you boot something like MS-DOS, than wants the first sector?Boris wrote:if you need to load elfs before paging, why not. Beware of two little things:
- Be sure you won't override used/non free physical ram. Yes, grub doesn't that. you can load your kernel at 0xB8000 and literally see what happens.
- When you activate paging, relocations you have you did before will be broken. I don't suggest you running your elf code after .