This is a continuation on the subject of executable sizes produced by GCC discussed here:
http://forum.tinycorelinux.net/index.php/topic,23134.msg144872.html#msg144872The linker (ld) uses a script to determine how it will create the output file. Those scripts are in:
/usr/local/lib/ldscripts/
If you don't specify which linker script to use, it defaults to the built in script. To determine which
which script is built in, first find the scripts description string:
tc@E310:~$ ld --verbose | grep -F "/* Script for "
/* Script for -z combreloc -z separate-code: combine and sort reloc sections with separate code segment */
A search for that string in the linker scripts directory tells us it defaults to the .xce script:
tc@E310:~$ grep -F "/* Script for -z combreloc -z separate-code: combine and sort reloc sections with separate code segment */" /usr/local/lib/ldscripts/*
/usr/local/lib/ldscripts/elf32_x86_64.xce:/* Script for -z combreloc -z separate-code: combine and sort reloc sections with separate code segment */
/usr/local/lib/ldscripts/elf_i386.xce:/* Script for -z combreloc -z separate-code: combine and sort reloc sections with separate code segment */
/usr/local/lib/ldscripts/elf_iamcu.xce:/* Script for -z combreloc -z separate-code: combine and sort reloc sections with separate code segment */
/usr/local/lib/ldscripts/elf_k1om.xce:/* Script for -z combreloc -z separate-code: combine and sort reloc sections with separate code segment */
/usr/local/lib/ldscripts/elf_l1om.xce:/* Script for -z combreloc -z separate-code: combine and sort reloc sections with separate code segment */
/usr/local/lib/ldscripts/elf_x86_64.xce:/* Script for -z combreloc -z separate-code: combine and sort reloc sections with separate code segment */
tc@E310:~$
The "descriptions" of the available scripts are:
tc@E310:~$ grep -F "/* Script for" /usr/local/lib/ldscripts/elf_i386.* | cut -d'/' -f6- | column -s: -t
elf_i386.xbn /* Script for -N mix text and data on same page; don't align data */
elf_i386.xc /* Script for -z combreloc combine and sort reloc sections */
elf_i386.xce /* Script for -z combreloc -z separate-code combine and sort reloc sections with separate code segment */
elf_i386.xd /* Script for ld -pie link position independent executable */
elf_i386.xdc /* Script for -pie -z combreloc position independent executable, combine & sort relocs */
elf_i386.xdce /* Script for -pie -z combreloc -z separate-code position independent executable, combine & sort relocs with separate code segment */
elf_i386.xde /* Script for ld -pie -z separate-code link position independent executable with separate code segment */
elf_i386.xdw /* Script for -pie -z combreloc -z now -z relro position independent executable, combine & sort relocs */
elf_i386.xdwe /* Script for -pie -z combreloc -z now -z relro -z separate-code position independent executable, combine & sort relocs with separate code segment */
elf_i386.xe /* Script for -z separate-code generate normal executables with separate code segment */
elf_i386.xn /* Script for -n mix text and data on same page */
elf_i386.xr /* Script for ld -r link without relocation */
elf_i386.xs /* Script for ld --shared link shared library */
elf_i386.xsc /* Script for --shared -z combreloc shared library, combine & sort relocs */
elf_i386.xsce /* Script for --shared -z combreloc -z separate-code shared library, combine & sort relocs with separate code segment */
elf_i386.xse /* Script for ld --shared -z separate-code link shared library with separate code segment */
elf_i386.xsw /* Script for --shared -z combreloc -z now -z relro shared library, combine & sort relocs */
elf_i386.xswe /* Script for --shared -z combreloc -z now -z relro -z separate-code shared library, combine & sort relocs with separate code segment */
elf_i386.xu /* Script for ld -Ur link w/out relocation, do create constructors */
elf_i386.xw /* Script for -z combreloc -z now -z relro combine and sort reloc sections */
elf_i386.xwe /* Script for -z combreloc -z now -z relro -z separate-code combine and sort reloc sections with separate code segment */
tc@E310:~$
I couldn't find anything that explained when and why you might want to use one over another.
What I
think I know is:
1. elf_i386.xce This is the current default for the linker in TC10. The "with separate code segment"
part of the description probably accounts for the larger executables.
2. elf_i386.xc This is the version the linker used in TC4. It produced smaller executables. The most
dramatic difference is when compiling programs that are small to begin with.
3. elf_i386.xbn This version appears to produce the smallest executables. The description reminds me of the
old DOS .com programs that were limited to 64K because they shared a code and data segment.
The "don't align data" part of the description may indicate it's not the best choice
for high performance applications.
I ran a few test compilations with the 3 scripts. The columns show the unstripped and sstripped sizes
with a plain, an added -fno-plt optimization, and an added -fno-plt -flto optimization.
This is a very small program that generates the rotating dash for Tinycore scripts:
gcc -flto -march=i486 -mtune=i686 -Os -pipe -Wall -fno-plt rotdash.c -o rotdash -Wl,-T/usr/local/lib/ldscripts/elf_i386.xbn
script rotdash sstripped -fno-plt sstripped -flto sstripped
elf_i386.xce 15324 12332 15304 12312 15276 12312
elf_i386.xc 7132 4140 7112 4120 7084 4120
elf_i386.xbn 4704 1656 4640 1592 4612 1592
This is a small program for hiding/moving the mouse cursor. It's also linked to some X libraries:
gcc -flto -fuse-linker-plugin -march=i486 -mtune=i686 -Os -g -pipe -Wall -Wextra -fno-plt -c HideMouse.c
gcc -Wl,-T/usr/local/lib/ldscripts/elf_i386.xbn -I. -L. HideMouse.o -o HideMouse -lX11 -lXfixes
script HideMouse sstripped -fno-plt sstripped -flto sstripped
elf_i386.xce 23660 12376 23608 12312 21540 12312
elf_i386.xc 15468 4184 15416 4120 13348 4120
elf_i386.xbn 14560 3284 14352 3064 12272 3048
This is a modestly sized screen grabber program. The -fwhole-program doesn't leave much for -flto to do:
gcc -flto -march=i486 -mtune=i686 -Os -g -pipe -Wall -Wextra -fno-plt -fwhole-program -c grabber.c
gcc -Wl,-T/usr/local/lib/ldscripts/elf_i386.xbn -I. -L. grabber.o -o grabber -lImlib2 -lX11 -lXfixes
script grabber sstripped -fno-plt sstripped -flto sstripped
elf_i386.xce 48192 16624 47984 16408 40052 16408
elf_i386.xc 44096 12528 43888 12312 35956 12312
elf_i386.xbn 42184 10620 41392 9820 33444 9804
Given a screw size and depth of thread, returns a chart containing the closest sized drills and the depth
of thread they would produce. It includes a large data structure of fractional, number, and letter drill sizes:
gcc -flto -march=i486 -mtune=i686 -Os -g -pipe -Wall -Wextra -fno-plt TapDrill.c -o TapDrill -Wl,-T/usr/local/lib/ldscripts/elf_i386.xbn
script TapDrill sstripped -fno-plt sstripped -flto sstripped
elf_i386.xce 31360 18592 31344 18560 31920 18528
elf_i386.xc 27264 14496 27248 14464 27824 14432
elf_i386.xbn 26872 14048 26792 13952 27368 13920
gpicview is described as:
A Simple and Fast GTK2 based Image Viewer
It is from the LXDE desktop package.
CFLAGS=" -flto -march=i486 -mtune=i686 -Os -pipe -fno-plt"
LDFLAGS="-Wl,-T/usr/local/lib/ldscripts/elf_i386.xbn"
script gpicview sstripped -fno-plt sstripped -flto sstripped
elf_i386.xce 93856 72278 88480 66902 82136 62452
elf_i386.xc 89760 68182 84384 62806 78040 58356
elf_i386.xbn 87416 65782 83256 61622 75728 55988
[EDIT]: Added gpicview table. Rich