How do I disable all libaries (including runtime)?

Programming, for all ages and all languages.
SoulofDeity
Member
Member
Posts: 193
Joined: Wed Jan 11, 2012 6:10 pm

How do I disable all libaries (including runtime)?

Post 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.
User avatar
Jezze
Member
Member
Posts: 395
Joined: Thu Jul 26, 2007 1:53 am
Libera.chat IRC: jfu
Contact:

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

Post by Jezze »

-ffreestanding?
Fudge - Simplicity, clarity and speed.
http://github.com/Jezze/fudge/
SoulofDeity
Member
Member
Posts: 193
Joined: Wed Jan 11, 2012 6:10 pm

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

Post by SoulofDeity »

Jezze wrote:-ffreestanding?
just tried it, no luck :(
User avatar
xenos
Member
Member
Posts: 1118
Joined: Thu Aug 11, 2005 11:00 pm
Libera.chat IRC: xenos1984
Location: Tartu, Estonia
Contact:

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

Post by xenos »

-fno-exceptions ?
Programmers' Hardware Database // GitHub user: xenos1984; OS project: NOS
SoulofDeity
Member
Member
Posts: 193
Joined: Wed Jan 11, 2012 6:10 pm

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

Post 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.
User avatar
dozniak
Member
Member
Posts: 723
Joined: Thu Jul 12, 2012 7:29 am
Location: Tallinn, Estonia

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

Post by dozniak »

Build a cross-compiler.
Learn to read.
SoulofDeity
Member
Member
Posts: 193
Joined: Wed Jan 11, 2012 6:10 pm

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

Post 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.
User avatar
Griwes
Member
Member
Posts: 374
Joined: Sat Jul 30, 2011 10:07 am
Libera.chat IRC: Griwes
Location: Wrocław/Racibórz, Poland
Contact:

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

Post 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.
Reaver Project :: Repository :: Ohloh project page
<klange> This is a horror story about what happens when you need a hammer and all you have is the skulls of the damned.
<drake1> as long as the lock is read and modified by atomic operations
SoulofDeity
Member
Member
Posts: 193
Joined: Wed Jan 11, 2012 6:10 pm

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

Post 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.
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

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

Post 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.
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

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

Post 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.
If a trainstation is where trains stop, what is a workstation ?
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

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

Post 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.
SoulofDeity
Member
Member
Posts: 193
Joined: Wed Jan 11, 2012 6:10 pm

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

Post 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.
User avatar
xenos
Member
Member
Posts: 1118
Joined: Thu Aug 11, 2005 11:00 pm
Libera.chat IRC: xenos1984
Location: Tartu, Estonia
Contact:

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

Post 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)?
Programmers' Hardware Database // GitHub user: xenos1984; OS project: NOS
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

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

Post 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.
Locked