OS-specific GCC options and ELF data?

Programming, for all ages and all languages.
Post Reply
mariuszp
Member
Member
Posts: 587
Joined: Sat Oct 16, 2010 3:38 pm

OS-specific GCC options and ELF data?

Post by mariuszp »

Has anyone been able to add OS-sepcific options to GCC? For example some option like "-mgui" to mark an executable as a GUI application instead of a console application? Or perhaps adding an icon to the executable, and then my OS could recognise those specific options written into an ELF file.

Where do I start?
User avatar
Roman
Member
Member
Posts: 568
Joined: Thu Mar 27, 2014 3:57 am
Location: Moscow, Russia
Contact:

Re: OS-specific GCC options and ELF data?

Post by Roman »

I see two options:
• write your own tool to modify executables after creating them (you might want to use libbfd, libelf or something similar);
• write a GCC plugin.

I would push that information into a section called something like ".glidix.info".
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
- Alan Kay
mariuszp
Member
Member
Posts: 587
Joined: Sat Oct 16, 2010 3:38 pm

Re: OS-specific GCC options and ELF data?

Post by mariuszp »

then i suppose the simplest solution is to create a tool which produces object files with a ".glidix.info" section in them and linking them in. But then, does the linker by default include such section in the executable, or does it remove it unless I explicitly put it in the linker script?
User avatar
Roman
Member
Member
Posts: 568
Joined: Thu Mar 27, 2014 3:57 am
Location: Moscow, Russia
Contact:

Re: OS-specific GCC options and ELF data?

Post by Roman »

Why not modify the executables after linking?
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
- Alan Kay
Boris
Member
Member
Posts: 145
Joined: Sat Nov 07, 2015 3:12 pm

Re: OS-specific GCC options and ELF data?

Post by Boris »

Do you have two ABIs ? why would you want to differentiate something that rune in console, your compositor or someone else's?
What is a console app ? something that expect standard output or write output ?
What is a GUI app ? something that talks to your compositor ?
What about apps that so the two things , like git when it uses a GUI keyring ? Or gnuplot: no window are shown until you enter a formula in console ?
Or qemu where you tell it to output serial in console and you don't want it's GUI?
mariuszp
Member
Member
Posts: 587
Joined: Sat Oct 16, 2010 3:38 pm

Re: OS-specific GCC options and ELF data?

Post by mariuszp »

Boris wrote:Do you have two ABIs ? why would you want to differentiate something that rune in console, your compositor or someone else's?
What is a console app ? something that expect standard output or write output ?
What is a GUI app ? something that talks to your compositor ?
What about apps that so the two things , like git when it uses a GUI keyring ? Or gnuplot: no window are shown until you enter a formula in console ?
Or qemu where you tell it to output serial in console and you don't want it's GUI?
It would be useful to let the file manager determine whether it should open a terminal for a "console application" when running it. And also embedding icons so that, again, the file manager could display them.
User avatar
Roman
Member
Member
Posts: 568
Joined: Thu Mar 27, 2014 3:57 am
Location: Moscow, Russia
Contact:

Re: OS-specific GCC options and ELF data?

Post by Roman »

You can also consider following macOS' approach: use app bundles. Simple executables without them would be executed with a terminal, those with app bundles wouldn't. Or you could store your options in a configuration file inside the bundle.
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
- Alan Kay
WeirdEdEdison
Posts: 5
Joined: Sat Feb 22, 2014 6:42 am

Re: OS-specific GCC options and ELF data?

Post by WeirdEdEdison »

Well, ELF allows you to add custom sections, e.g. a resource section. Compile your resource script into an ELF object file with the resource data in a custom section and use a linker script to have ld include that section into your program executable. You could add different sections as well, e.g. certificates to prevent the OS from running unsigned programs, or metadata for COM style type libraries.

As for the console vs. GUI aspect, you could simply have different runtime startup code. Console applications can test if the standard I/O handles (stdout, stdin and stderr) are open, if not, they can create a new terminal window and bind the standard I/O handles to this window.
Post Reply