Page 1 of 3

How do I disable all libaries (including runtime)?

Posted: Sun Nov 11, 2012 4:05 pm
by SoulofDeity
My operating system so far has been written entirely in assembly and has grown a bit of dust actually...I haven't touched it in months.

Anyway, I've screwed around a lot on my pc since then and ended up deleting my old cross compiler, and now I'm wanting to rewrite the kernel part in C. I don't feel like waiting 8 hours to install cygwin and rebuild it, and I'm also wanting to create my own binary format.
The plan is to disable all libraries (including runtime) and just build the application with MinGW, and then use a program that converts a PE binary to my own format.

The problem is I can't turn off the libraries -_-

here's the options I've been passing to the compiler:

-nostdlib -fno-builtin -nostartfiles -nodefaultlibs -Wl,-n,-S,--strip-discarded,-dn,--gc-sections,-nostdlib,-rpath,.,-rpath-link,.,--file-alignment,0,--section-alignment,0,--disable-runtime-pseudo-reloc

The kernel itself it just an empty main function right now, and the binary is 3KB in size. Looking at it in a hex editor, there are symbols like "___RUNTIME_PSEUDO_RELOC_LIST__" which shouldn't be there because I'm using "--disable-runtime-pseudo-reloc".

If I strip all symbols the image size goes down to 1KB, but there's still 2 sections that shouldn't be there called ".eh_fram8" and ".idata".



Can someone please tell me how to disable this stupid runtime library? #-o


PS. Please don't tell me to just make a cross compiler or just use elf files for my binaries. I want to use my own binary format for my own personal reasons, and if I'm going to have to convert the binaries anyway, it doesn't make much sense to waste my time making a cross compiler when I already have a perfectly good i586 compiler installed.

Re: How do I disable all libaries (including runtime)?

Posted: Sun Nov 11, 2012 4:22 pm
by Jezze
-ffreestanding?

Re: How do I disable all libaries (including runtime)?

Posted: Sun Nov 11, 2012 4:24 pm
by SoulofDeity
Jezze wrote:-ffreestanding?
just tried it, no luck :(

Re: How do I disable all libaries (including runtime)?

Posted: Sun Nov 11, 2012 4:45 pm
by xenos
-fno-exceptions ?

Re: How do I disable all libaries (including runtime)?

Posted: Sun Nov 11, 2012 4:51 pm
by SoulofDeity
XenOS wrote:-fno-exceptions ?
still no luck.

I'm starting to think that creators of MinGW disabled the ability to disable standard libraries. I've been googling for 2-3 hours now and nothing seems to work.

Re: How do I disable all libaries (including runtime)?

Posted: Sun Nov 11, 2012 5:20 pm
by dozniak
Build a cross-compiler.

Re: How do I disable all libaries (including runtime)?

Posted: Sun Nov 11, 2012 5:33 pm
by SoulofDeity
dozniak wrote:Build a cross-compiler.
I just said in the first post I'm not doing that. It's pointless. The binary format isn't going to matter because I'm using my own, so it makes no sense to build an i586 compiler when I already have one.

I've been experimenting with TCC the past few minutes, and so far the only problem I get is an undefined reference to '_start' which disappears if I create functions for both '_start' and '__start'.
If I can fix that small problem, I'll just use that.

Re: How do I disable all libaries (including runtime)?

Posted: Sun Nov 11, 2012 5:52 pm
by Griwes
If you are going to just say "your way sucks", why are you even asking?

Pro-tip: cross-compiling is THE way to go with GCC.

Re: How do I disable all libaries (including runtime)?

Posted: Sun Nov 11, 2012 6:27 pm
by SoulofDeity
Griwes wrote:If you are going to just say "your way sucks", why are you even asking?

Pro-tip: cross-compiling is THE way to go with GCC.
I stated in my first post that I wasn't going to build a GCC cross compiler, and politely asked that people not even suggest it.

btw, your "pro-tip" is a "noob-tip". it's not that I don't know how to build one, I've built cross-compilers for arm, mips, i368, and x86_64 tons of times. the point is that right now, I don't want to waste 8 hours of my time doing it again when all I need to do is pass a switch to my current compiler and save myself a few hours of boredom.

Re: How do I disable all libaries (including runtime)?

Posted: Sun Nov 11, 2012 6:42 pm
by thepowersgang
The point is you can't just pass a switch to your compiler in some cases. Most distribution-provided compilers have patches that make them annoying to use for OSDev. In theory, all you need is -ffreestanding to disable all library references (note - you still need libgcc, but it's mostly system independent)

As for it taking 8 hours, a cross compiler build on my atom netbook takes about two hours from extraction to execution.

Re: How do I disable all libaries (including runtime)?

Posted: Sun Nov 11, 2012 7:45 pm
by gerryg400
thepowersgang wrote:As for it taking 8 hours, a cross compiler build on my atom netbook takes about two hours from extraction to execution.
A cross-compiler build on my machine (untar to install of binutils and gcc) takes less than 6 mins. No wonder people say that Cygwin is rubbish.

OP you must build a cross-compiler. There is actually no other way.

Re: How do I disable all libaries (including runtime)?

Posted: Sun Nov 11, 2012 9:18 pm
by bluemoon
SoulofDeity wrote:
dozniak wrote:Build a cross-compiler.
I just said in the first post I'm not doing that. It's pointless. The binary format isn't going to matter because I'm using my own, so it makes no sense to build an i586 compiler when I already have one.
You misunderstood the point of building cross compiler.
The whole point of cross compiler is not about executable format, but remove the system dependency from the development of your OS, as other suggested, some compiler has custom fixes that drag in platform dependent stuff that surprise you.
The general idea is, build a cross compiler, otherwise you are test pilot and know exactly what you are doing.

Re: How do I disable all libaries (including runtime)?

Posted: Sun Nov 11, 2012 11:15 pm
by SoulofDeity
bluemoon wrote:
SoulofDeity wrote:
dozniak wrote:Build a cross-compiler.
I just said in the first post I'm not doing that. It's pointless. The binary format isn't going to matter because I'm using my own, so it makes no sense to build an i586 compiler when I already have one.
You misunderstood the point of building cross compiler.
The whole point of cross compiler is not about executable format, but remove the system dependency from the development of your OS, as other suggested, some compiler has custom fixes that drag in platform dependent stuff that surprise you.
The general idea is, build a cross compiler, otherwise you are test pilot and know exactly what you are doing.
I don't see what other system dependent stuff there could be aside from calling methods (which in the case of windows is usually cdecl which I'll be using anyway), and as far as I know GCC generated code doesn't make use of interrupts.
Disabling standard libraries should be all you have to do to.

But anyway, seeing as how I have no choice, I'm just gonna customize TCC for my needs and build that instead downloading cygwin and going through that ridiculously long process. Then I can just make it output my own format from the get-go and kill 2 birds with 1 stone.

EDIT:
Btw, for me it takes
~45min to install cygwin with the default packages and gmp mpfr mpc flex & bison
~15min to download binutils and gcc
~5min to extract binutils
~10min to extract gcc
~1.5hr to build binutils
~2hr to build gcc
~30min to build libgcc

So it's really more like 5 hours than 8 hours, but still you get the point.

Re: How do I disable all libaries (including runtime)?

Posted: Sun Nov 11, 2012 11:31 pm
by xenos
SoulofDeity wrote:So it's really more like 5 hours than 8 hours, but still you get the point.
How much time did you spend playing around with command line switches, trying to solve the problem without a cross compiler? Is it really easier and less time consuming than following a way that is known to be working (even though it takes a few hours)?

Re: How do I disable all libaries (including runtime)?

Posted: Mon Nov 12, 2012 12:26 am
by bluemoon
SoulofDeity wrote:I don't see what other system dependent stuff there could be aside from calling methods (which in the case of windows is usually cdecl which I'll be using anyway), and as far as I know GCC generated code doesn't make use of interrupts.
Disabling standard libraries should be all you have to do to.
I'm not begin rude but please forgive me, I don't know how to say it better.
This is a typical "I know it inside out, and now I ask a question, but your solution is invalid because I don't see anything."

Anyway, some platform bundled compiler will drag in system-specific header and libraries (mostly linux-introduced stuff), or trying to link with system libraries even for freestanding flags, or put in unexpected default values on executable generation process; which usually conflict/surprise almost all OS development. You may use host compiler in some platform, but then it is a moving target and require a lot of testing and therefore most people simply tell you to use a cross-compiler to make your life easier.