GCC insert custom section data into ELF binary

Programming, for all ages and all languages.
Post Reply
User avatar
AndrewAPrice
Member
Member
Posts: 2300
Joined: Mon Jun 05, 2006 11:00 pm
Location: USA (and Australia)

GCC insert custom section data into ELF binary

Post by AndrewAPrice »

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.
My OS is Perception.
nullplan
Member
Member
Posts: 1790
Joined: Wed Aug 30, 2017 8:24 am

Re: GCC insert custom section data into ELF binary

Post by nullplan »

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.
Carpe diem!
User avatar
AndrewAPrice
Member
Member
Posts: 2300
Joined: Mon Jun 05, 2006 11:00 pm
Location: USA (and Australia)

Re: GCC insert custom section data into ELF binary

Post by AndrewAPrice »

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".
My OS is Perception.
User avatar
AndrewAPrice
Member
Member
Posts: 2300
Joined: Mon Jun 05, 2006 11:00 pm
Location: USA (and Australia)

Re: GCC insert custom section data into ELF binary

Post by AndrewAPrice »

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.
My OS is Perception.
Post Reply