OSDev.org
https://forum.osdev.org/

GCC insert custom section data into ELF binary
https://forum.osdev.org/viewtopic.php?f=13&t=36754
Page 1 of 1

Author:  AndrewAPrice [ Wed May 13, 2020 12:17 pm ]
Post subject:  GCC insert custom section data into ELF binary

Is it possible, someway in C/C++ code in GCC, to define data that can be put into custom sections in an ELF binary?

I was wondering if it was possible for userland services in my OS to expose a list of RPC entry points, even if the process isn't yet loaded and running in memory.

Author:  nullplan [ Wed May 13, 2020 12:35 pm ]
Post subject:  Re: GCC insert custom section data into ELF binary

AndrewAPrice wrote:
Is it possible, someway in C/C++ code in GCC, to define data that can be put into custom sections in an ELF binary?

__attribute__((section("foo")))

AndrewAPrice wrote:
I was wondering if it was possible for userland services in my OS to expose a list of RPC entry points, even if the process isn't yet loaded and running in memory.

Sections are not necessarily a feature of executables. There might be a special segment, but then you're going into special linker script territory. But why would you not just run the binary and have it register such a list with your kernel? Seems simpler to me.

Author:  AndrewAPrice [ Wed May 13, 2020 1:55 pm ]
Post subject:  Re: GCC insert custom section data into ELF binary

Thanks! It seems easy enough to tag a struct and even initialize it with a constexpr.

AndrewAPrice wrote:
But why would you not just run the binary and have it register such a list with your kernel?


It's just one of many possibilities I'm evaluating for working around the race condition of a service starting (e.g. the VFS), and then, say an essential driver that's part of the initialization process (such as the video card) that wants to call "VFS.ReadFile" to read some configuration file, if the main thread of the VFS was preempted before getting around to register "VFS.ReadFile".

Author:  AndrewAPrice [ Wed May 13, 2020 3:12 pm ]
Post subject:  Re: GCC insert custom section data into ELF binary

I think it would be best if I solved this problem another way - registering RPCs with the kernel but sending an "initialized" message when the process is ready to receive calls. Then drivers can say "get Device Manager and wait for it to be initialized, timeout after 5s".

Then I can start my system with a "Process Soup" - a bunch of multiboot modules essential services and drivers, and they can sleep until their dependencies are initialized.

The custom ELF sections would still let us do interesting stuff such as examine what RPCs a process would expose without launching it.

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/