freebasic / fbc

FreeBASIC is a completely free, open-source, multi-platform BASIC compiler, with syntax similar to MS-QuickBASIC, that adds new features such as pointers, object orientation, unsigned data types, inline assembly, and many others.
https://www.freebasic.net
877 stars 137 forks source link

Brecht Sanders MinGW-W64 refrence possibly rather excessive in compiled exe with gcc #421

Closed thrive4 closed 10 months ago

thrive4 commented 11 months ago

Well first of I ascribe to the notion that 'credit where credit's due' is given but it seems that when compiled even very simple pieces of code generate quite a lot of references to: GCC: (MinGW-W64 i686-posix-sjlj, built by Brecht Sanders) 9.3.0

Take the code I posted in a previous post: https://github.com/freebasic/fbc/issues/420 when compiled it contains roughly 4k of references to: GCC: (MinGW-W64 i686-posix-sjlj, built by Brecht Sanders) 9.3.0 Compile option -s console -w none

The more elaborate the code becomes the higher the amount, can, be become....

Might be worth looking into because an other notion worth ascribing to is 'waste not want not' ;)

SARG-FB commented 11 months ago

I posted a solution on the forum. Did you see it ?

thrive4 commented 11 months ago

@SARG Thank you for passing on this solution / workaround! I've tried it on various projects I have made, and the reduction in filesize varies to an quite substantial degree.

For instance one case went from ~400KB to ~380KB a reduction of ~20KB by adding *(.rdata$zzz) as you suggested.

Just for clarity is there a specific reason why this is not set in the default build of FB?

I have noticed it completely removes all the references to GCC: (MinGW-W64 i686-posix-sjlj, built by Brecht Sanders) 9.3.0 I still think one time would be civil, possibly by using a readme.txt or other external file.

Anyway I will definitely be using this approach, I hope that it somehow becomes part of the upcoming 1.20 release of FB for now many thanks once again for passing this info on!

SARG-FB commented 11 months ago

You are welcome.

why this is not set in the default build of FB?

Just because noone seems annoyed by this and file sizes are not a real problem except when loading executable ;-) Even if I saw that 'garbage' I didn't look to remove it before. Anyway I posted a message to jeff (lead dev) and I'll see with him the best way to proceed. And yes adding a text to name Sanders should a good thing.

jayrm commented 11 months ago

Related: https://github.com/niXman/mingw-builds/issues/412 https://github.com/msys2/MINGW-packages/issues/21

In short, gcc emits an .ident field that adds string text to every module and it isn't merged to one single string in the output. Appears that this can be disabled with gcc -fno-ident ..., but only when compiling from source.

Example comparison of generating .rdata$zzz section or not using -fno-ident gcc option:

> gcc -c a.c && nm a.o
00000000 b .bss
00000000 d .data
00000000 r .rdata$zzz
00000000 t .text
00000000 T _func

> gcc -c a.c -fno-ident && nm a.o
00000000 b .bss
00000000 d .data
00000000 t .text
00000000 T _func

For fbc project itself:

For the supporting libraries from the prebuilt toolchain:

thrive4 commented 11 months ago

All righty... First many thanks to both sarg-fb and jayrm aka coderjeff for looking into this and the effort for coming up with possible solutions / workarounds.

I had a slight suspicion that there would be more to this then meets the eye, good to read about the licensing specific aspect, and hope that the '-fno-ident' option resolves this issue for all parties concerned.

So the *(.rdata$zzz) mod to fbextra.x as sarg aka sarg-fb suggested for fbc 1.09 ~ fb 1.10 https://www.freebasic.net/forum/viewtopic.php?t=32254&start=45 and from fbc 1.20 compiling with'-fno-ident' will suffice?

Bye the bye since 2014... https://github.com/msys2/MINGW-packages/issues/21 Sic Parvis Magna...

jayrm commented 11 months ago

@thrive4

and from fbc 1.20 compiling with '-fno-ident' will suffice?

Not entirely. Depends on the toolchain used to compile any of the supporting static libraries or object modules. If the supporting libraries were compiled with the .ident string, then -fno-pic -fno-ident won't remove those.

We could add discarding *(.rdata$zzz) to fbextra.x for fbc 1.20.0, but it would be nice to know if anything important gets stored there.

Edit: oops, meant to write -fno-ident above instead of -fno-pic.

Rinat84 commented 11 months ago

Something like this. Excluded FFI, compiled for example. freebasic.zip

jayrm commented 10 months ago

Added gcc option -fno-ident when compiling under windows: In fbc-1.20.0 see commit: [e6bc5cc7c37cb345d1bf704be9db5b73228c58c7]

In hindsight, I should have probably added to fbc-1.10.1 branch first and then merged in to fbc-1.20. So instead, I will follow this up with a cherry-pick to fbc-1.10.1 and then a merge later.

jayrm commented 10 months ago

fbc-1.20.0 commit: [e6bc5cc7c37cb345d1bf704be9db5b73228c58c7] cherry picked to fbc-1.10 branch in commit: [a146bd876db2e2994773b020f180beb25375e8ab]

Next releases will have the -fno-ident option by default for windows.

I believe we can consider this issue closed.