WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: GCC compiler and linker options  (Read 5235 times)

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11518
GCC compiler and linker options
« on: March 16, 2020, 01:44:22 AM »
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#msg144872

The linker (ld) uses a script to determine how it will create the output file. Those scripts are in:
Code: [Select]
/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:
Code: [Select]
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:
Code: [Select]
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:
Code: [Select]
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:
Code: [Select]
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:
Code: [Select]
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:
Code: [Select]
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:
Code: [Select]
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.
Code: [Select]
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
« Last Edit: March 28, 2020, 10:44:32 AM by Rich »

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11518
Re: GCC compiler and linker options
« Reply #1 on: March 17, 2020, 12:16:09 AM »
I decided to rerun the tests using CorePure64-10.1 to see how these options fare in a 64 bit environment.

Code: [Select]
gcc -flto -mtune=generic -Os -pipe -Wall -fno-plt rotdash.c -o rotdash -Wl,-T/usr/local/lib/ldscripts/elf_x86_64.xbn

script            rotdash  sstripped  -fno-plt  sstripped    -flto  sstripped
elf_x86_64.xce      16656      12368     16432      12328    16400      12328
elf_x86_64.xc        8464       4176      8240       4136     8208       4136
elf_x86_64.xbn       6952       2576      6576       2384     6544       2384

Code: [Select]
gcc -flto -mtune=generic -Os -g -pipe -Wall -Wextra -fno-plt -c HideMouse.c
gcc -Wl,-T/usr/local/lib/ldscripts/elf_x86_64.xbn -I. -L. HideMouse.o -o HideMouse -lX11 -lXfixes

script          HideMouse  sstripped  -fno-plt  sstripped    -flto  sstripped
elf_x86_64.xce      26056      12456     25752      12328    23056      12328
elf_x86_64.xc       21960       8360     21656       8232    18960       8232
elf_x86_64.xbn      18264       4672     17712       4296    15008       4288

Code: [Select]
gcc -flto -mtune=generic -Os -g -pipe -Wall -Wextra -fno-plt -fwhole-program -c grabber.c
gcc -Wl,-T/usr/local/lib/ldscripts/elf_x86_64.xbn -I. -L. grabber.o -o grabber -lImlib2 -lX11 -lXfixes

script            grabber  sstripped  -fno-plt  sstripped    -flto  sstripped
elf_x86_64.xce      57584      21296     56968      20848    46360      20520
elf_x86_64.xc       53488      17200     52872      16752    42264      16424
elf_x86_64.xbn      49832      13552     48800      12688    38488      12656

Code: [Select]
gcc -flto -mtune=generic-Os -g -pipe -Wall -Wextra -fno-plt TapDrill.c -o TapDrill -Wl,-T/usr/local/lib/ldscripts/elf_x86_64.xbn

script           TapDrill  sstripped  -fno-plt  sstripped    -flto  sstripped
elf_x86_64.xce      41136      25840     40896      25776    41680      25712
elf_x86_64.xc       37040      21744     36800      21680    37584      21616
elf_x86_64.xbn      33576      18192     33112      17904    33928      17872

I didn't feel like running all the combinations for gpicview, so here are the highlights, sstripped numbers only:
Code: [Select]
CFLAGS=" -mtune=generic -Os -pipe "
LDFLAGS="-Wl,-O1"
90530

CFLAGS=" -mtune=generic -Os -pipe "
LDFLAGS="-Wl,-T/usr/local/lib/ldscripts/elf_x86_64.xbn"
83362

CFLAGS=" -flto -mtune=generic -Os -pipe -fno-plt"
LDFLAGS="-Wl,-T/usr/local/lib/ldscripts/elf_x86_64.xbn"
70096

The improvements were very similar to the 32 bit tests.

I would say using the  .xbn  linker script and  sstrip  by far provided the largest reduction in executable size.
Adding  -fno-plt  to that saved between 64 and 800 bytes for 32 bits and between 192 and 864 bytes for 64 bits.
Adding  -flto  to the mix only saved between 0 and 32 additional bytes for both 32 and 64 bits.

    [EDIT]: Added results for gpicview.  Rich
« Last Edit: March 28, 2020, 11:05:56 AM by Rich »

Offline andyj

  • Hero Member
  • *****
  • Posts: 1036
Re: GCC compiler and linker options
« Reply #2 on: March 17, 2020, 07:44:10 AM »
Have you done any speed tests?
How about with larger executable images?
Does space saving scale or flatten out?
How is compile time affected?
Have you tried this on the kernel?
It would be interesting to see how Xorg and DRM/3D would be affected. I could probably get around to trying it out on some databases or web servers, but I'd need to find some benchmark suites first.

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14756
Re: GCC compiler and linker options
« Reply #3 on: March 17, 2020, 10:10:45 AM »
In testing a few years back, I found -flto made large apps 5-10% smaller (except for static libs, which it makes 10x bigger).

Removing "-g -O2", which autotools puts in most Makefiles also makes things smaller.

I see librsvg now needs rustc and is 3x larger...

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11518
Re: GCC compiler and linker options
« Reply #4 on: March 17, 2020, 10:53:52 AM »
Hi andyj
Have you done any speed tests?
No.

Quote
How about with larger executable images?
Not yet. I'm going to try with  lshw  and  gtk-lshw.  The current executables are about 944K and 1228K respectively and were compiled
with the  -flto  option.

On a side note, I read on StackOverflow that  -flto  could be used in place of  -flto -fuse-linker-plugin  because it now causes
-fuse-linker-plugin  to be used automatically.  I tested it and adding  -fuse-linker-plugin  to  -flto  made no difference.


Quote
Does space saving scale or flatten out?
The last 2 programs (grabber and TapDrill) are similar in size and complexity. One difference is TapDrill contains an array of
386  16 byte structures (6167 Bytes) preloaded with text and floating point values. I suspect there's not much that can be
optimized in that part of the program.

Quote
How is compile time affected?
I didn't time it.

I wouldn't expect the linker script to make any difference. It just provides guidance on gaps between sections, location of sections,
section alignment, etc. It doesn't deal with code optimization.

The  -fno-plt  just strips out some stub code. The end effect is (from gcc.org) "all external symbols are resolved at load time". That
means load time may be slower. Whether that's noticeable is another question. It also frees up a register in 32 bit x86.

Quote
Have you tried this on the kernel?
The only kernel tinkering I've done is through  make menuconfig.

Quote
It would be interesting to see how Xorg and DRM/3D would be affected. I could probably get around to trying it out on some databases or web servers, but I'd need to find some benchmark suites first.
Remember what I said about the  .xbn  script:
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.
If there is a serious performance hit, go with the  .xc.  script.

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11518
Re: GCC compiler and linker options
« Reply #5 on: March 28, 2020, 11:40:43 AM »
Hi andyj
Quote
How about with larger executable images?
Not yet. I'm going to try with  lshw  and  gtk-lshw.  The current executables are about 944K and 1228K respectively and were compiled
with the  -flto  option.
Turns out the  lshw  package ignores any  CFLAGS  and  CXXFLAGS  values you set, and I don't feel like breaking the  Makefile.

I did do some tests on  gpicview.  Results are appended to the first 2 posts. There was 1 interesting surprise.

Previous examples had this type of result:

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

Big gain going from  .xce (16624)  to  .xbn (10620).  Adding  -fno-plt  and  -flto  shrunk it a tiny bit more (9804).

The  gpicview  program responded differently:

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

Modest gain going from  .xce (72278)  to  .xbn (65782).  Adding  -fno-plt  and  -flto  shrunk it quite a bit more (55988).

The 64 bit version of  gpicview  had similar results:
Modest gain going from  .xce (90530)  to  .xbn (83362).  Adding  -fno-plt  and  -flto  shrunk it quite a bit more (70096).

Offline jazzbiker

  • Hero Member
  • *****
  • Posts: 934
Re: GCC compiler and linker options
« Reply #6 on: April 21, 2020, 12:49:04 PM »
Hi, Rich!

Thank You for the great investigation on linker scripts properties. You inspire and encourage to continue the haunt. I chose mpg123 package, because repo version is old enough and maybe it is time to refresh it a little, and make some experiments along with.
Frankly speaking the results seems to me quite amazing and somewhat unpredicted, for me personally.
So I took the latest release mpg123-1.15.13 sources from the project site and worked with them. Resulting extension consists not only of the executable binary, but of some shared libs, and this shared libs appeared to behave controversial to binaries. speaking about their sizes.

Let me describe what I was doing. I made 8 variants of mpg123.tcz, using different CFLAGS and LDFLAGS, following Your advices. Then I packed all of them into 8 different extensions and used them later for memory consumption and performance testing.
The log and information about build process and sizes is the next:

Code: [Select]
Target=mpg123.1
CFLAGS=-march=i486 -mtune=i686
LDFLAGS=

real 2m 28.56s
user 2m 16.84s
sys 0m 13.23s

-rwxr-xr-x    1 root     root        123120 Apr 21 16:27 /tmp/mpg123.1/usr/local/bin/mpg123
-rwxr-xr-x    1 root     root        325688 Apr 21 16:27 /tmp/mpg123.1/usr/local/lib/libmpg123.so
-rwxr-xr-x    1 root     root         49408 Apr 21 16:27 /tmp/mpg123.1/usr/local/lib/libout123.so
-rwxr-xr-x    1 root     root         12452 Apr 21 16:27 /tmp/mpg123.1/usr/local/lib/mpg123/output_alsa.so
-rwxr-xr-x    1 root     root         12340 Apr 21 16:27 /tmp/mpg123.1/usr/local/lib/mpg123/output_dummy.so

-rw-r--r--    1 tc       staff       253952 Apr 21 16:27 ./mpg123.1.tcz

Target=mpg123.2
CFLAGS=-march=i486 -mtune=i686
LDFLAGS=-Wl,-T/usr/local/lib/ldscripts/elf_i386.xbn

real 2m 27.87s
user 2m 16.69s
sys 0m 12.89s

-rwxr-xr-x    1 root     root        114704 Apr 21 16:33 /tmp/mpg123.2/usr/local/bin/mpg123
-rwxr-xr-x    1 root     root        318776 Apr 21 16:33 /tmp/mpg123.2/usr/local/lib/libmpg123.so
-rwxr-xr-x    1 root     root         42344 Apr 21 16:33 /tmp/mpg123.2/usr/local/lib/libout123.so
-rwxr-xr-x    1 root     root          8404 Apr 21 16:33 /tmp/mpg123.2/usr/local/lib/mpg123/output_alsa.so
-rwxr-xr-x    1 root     root          1916 Apr 21 16:33 /tmp/mpg123.2/usr/local/lib/mpg123/output_dummy.so

-rw-r--r--    1 tc       staff       253952 Apr 21 16:33 ./mpg123.2.tcz

Target=mpg123.3
CFLAGS=-march=i486 -mtune=i686 -flto
LDFLAGS=

real 2m 50.05s
user 2m 36.95s
sys 0m 14.42s

-rwxr-xr-x    1 root     root        118156 Apr 21 16:39 /tmp/mpg123.3/usr/local/bin/mpg123
-rwxr-xr-x    1 root     root        346104 Apr 21 16:39 /tmp/mpg123.3/usr/local/lib/libmpg123.so
-rwxr-xr-x    1 root     root         57584 Apr 21 16:39 /tmp/mpg123.3/usr/local/lib/libout123.so
-rwxr-xr-x    1 root     root         12440 Apr 21 16:39 /tmp/mpg123.3/usr/local/lib/mpg123/output_alsa.so
-rwxr-xr-x    1 root     root         12328 Apr 21 16:39 /tmp/mpg123.3/usr/local/lib/mpg123/output_dummy.so

-rw-r--r--    1 tc       staff       266240 Apr 21 16:39 ./mpg123.3.tcz

Target=mpg123.4
CFLAGS=-march=i486 -mtune=i686 -flto
LDFLAGS=-Wl,-T/usr/local/lib/ldscripts/elf_i386.xbn

real 2m 49.30s
user 2m 36.62s
sys 0m 14.24s

-rwxr-xr-x    1 root     root        109068 Apr 21 16:45 /tmp/mpg123.4/usr/local/bin/mpg123
-rwxr-xr-x    1 root     root        343032 Apr 21 16:45 /tmp/mpg123.4/usr/local/lib/libmpg123.so
-rwxr-xr-x    1 root     root         50576 Apr 21 16:45 /tmp/mpg123.4/usr/local/lib/libout123.so
-rwxr-xr-x    1 root     root          8008 Apr 21 16:45 /tmp/mpg123.4/usr/local/lib/mpg123/output_alsa.so
-rwxr-xr-x    1 root     root          1492 Apr 21 16:45 /tmp/mpg123.4/usr/local/lib/mpg123/output_dummy.so

-rw-r--r--    1 tc       staff       266240 Apr 21 16:45 ./mpg123.4.tcz

Target=mpg123.5
CFLAGS=-march=i486 -mtune=i686 -flto -pipe
LDFLAGS=

real 2m 49.41s
user 2m 38.74s
sys 0m 14.56s

-rwxr-xr-x    1 root     root        118156 Apr 21 16:51 /tmp/mpg123.5/usr/local/bin/mpg123
-rwxr-xr-x    1 root     root        346104 Apr 21 16:51 /tmp/mpg123.5/usr/local/lib/libmpg123.so
-rwxr-xr-x    1 root     root         57584 Apr 21 16:51 /tmp/mpg123.5/usr/local/lib/libout123.so
-rwxr-xr-x    1 root     root         12440 Apr 21 16:51 /tmp/mpg123.5/usr/local/lib/mpg123/output_alsa.so
-rwxr-xr-x    1 root     root         12328 Apr 21 16:51 /tmp/mpg123.5/usr/local/lib/mpg123/output_dummy.so

-rw-r--r--    1 tc       staff       266240 Apr 21 16:51 ./mpg123.5.tcz

Target=mpg123.6
CFLAGS=-march=i486 -mtune=i686 -flto -pipe
LDFLAGS=-Wl,-T/usr/local/lib/ldscripts/elf_i386.xbn

real 2m 49.54s
user 2m 38.81s
sys 0m 14.59s

-rwxr-xr-x    1 root     root        109068 Apr 21 16:56 /tmp/mpg123.6/usr/local/bin/mpg123
-rwxr-xr-x    1 root     root        343032 Apr 21 16:56 /tmp/mpg123.6/usr/local/lib/libmpg123.so
-rwxr-xr-x    1 root     root         50576 Apr 21 16:56 /tmp/mpg123.6/usr/local/lib/libout123.so
-rwxr-xr-x    1 root     root          8008 Apr 21 16:56 /tmp/mpg123.6/usr/local/lib/mpg123/output_alsa.so
-rwxr-xr-x    1 root     root          1492 Apr 21 16:56 /tmp/mpg123.6/usr/local/lib/mpg123/output_dummy.so

-rw-r--r--    1 tc       staff       266240 Apr 21 16:56 ./mpg123.6.tcz

Target=mpg123.7
CFLAGS=-march=i486 -mtune=i686 -flto -pipe -fno-plt
LDFLAGS=

real 2m 46.47s
user 2m 35.82s
sys 0m 14.51s

-rwxr-xr-x    1 root     root        113420 Apr 21 17:02 /tmp/mpg123.7/usr/local/bin/mpg123
-rwxr-xr-x    1 root     root        345752 Apr 21 17:02 /tmp/mpg123.7/usr/local/lib/libmpg123.so
-rwxr-xr-x    1 root     root         57360 Apr 21 17:02 /tmp/mpg123.7/usr/local/lib/libout123.so
-rwxr-xr-x    1 root     root         12328 Apr 21 17:02 /tmp/mpg123.7/usr/local/lib/mpg123/output_alsa.so
-rwxr-xr-x    1 root     root         12328 Apr 21 17:02 /tmp/mpg123.7/usr/local/lib/mpg123/output_dummy.so

-rw-r--r--    1 tc       staff       262144 Apr 21 17:02 ./mpg123.7.tcz

Target=mpg123.8
CFLAGS=-march=i486 -mtune=i686 -flto -pipe -fno-plt
LDFLAGS=-Wl,-T/usr/local/lib/ldscripts/elf_i386.xbn

real 2m 45.88s
user 2m 35.56s
sys 0m 14.40s

-rwxr-xr-x    1 root     root        107436 Apr 21 17:06 /tmp/mpg123.8/usr/local/bin/mpg123
-rwxr-xr-x    1 root     root        341848 Apr 21 17:06 /tmp/mpg123.8/usr/local/lib/libmpg123.so
-rwxr-xr-x    1 root     root         50392 Apr 21 17:06 /tmp/mpg123.8/usr/local/lib/libout123.so
-rwxr-xr-x    1 root     root          7600 Apr 21 17:06 /tmp/mpg123.8/usr/local/lib/mpg123/output_alsa.so
-rwxr-xr-x    1 root     root          1492 Apr 21 17:06 /tmp/mpg123.8/usr/local/lib/mpg123/output_dummy.so

-rw-r--r--    1 tc       staff       262144 Apr 21 17:06 ./mpg123.8.tcz

For each set of CFLAGS and LDFLAGS compile time is given (this was andyj asked for) and sizes of resulting binaries and shared libs, and the resulting extension size.

Data were collected using script
Code: [Select]
#!/bin/sh
#
# CFLAGS ans LDFLAGS are set manually before the script execution
# install dir name is the parameter

OUT_DIR=${1:-"mpg123"}
LOGFILE="/home/tc/c/mpg123/build.log"


echo Target=$OUT_DIR >> "$LOGFILE"
echo CFLAGS=$CFLAGS >> "$LOGFILE"
echo LDFLAGS=$LDFLAGS >> "$LOGFILE"
echo  >> "$LOGFILE"

tce-load -i compiletc alsa-dev sstrip squashfs-tools

cd /tmp

sudo rm -r "$OUT_DIR"

cd mpg123-1.25.13

make clean

./configure --with-audio=alsa --with-default-audio=alsa

time -a -o "$LOGFILE" make

sudo make DESTDIR=/tmp/"$OUT_DIR" install

sudo rm -r /tmp/"$OUT_DIR"/usr/local/include
sudo rm -r /tmp/"$OUT_DIR"/usr/local/share
sudo rm -r /tmp/"$OUT_DIR"/usr/local/lib/pkgconfig

sudo find /tmp/"$OUT_DIR"/usr/local/bin -type f -a ! -name "mpg123" -delete

sudo find /tmp/"$OUT_DIR"/usr/local/bin -exec sstrip {} +
sudo find -L /tmp/"$OUT_DIR"/usr/local/lib -type f -a -name "*.so" -exec sstrip {} +

cd /tmp

rm -f "$OUT_DIR".tcz
mksquashfs "$OUT_DIR" "$OUT_DIR".tcz


echo  >> "$LOGFILE"
find /tmp/"$OUT_DIR"/usr/local/bin -type f -exec ls -l {} + >> "$LOGFILE"
find -L /tmp/"$OUT_DIR"/usr/local/lib -type f -a -name "*.so" -exec ls -lL {} + >> "$LOGFILE"

echo  >> "$LOGFILE"
find . -name "$OUT_DIR.tcz" -exec ls -l {} + >> "$LOGFILE"

echo  >> "$LOGFILE"

cd ~/c/mpg123

So whats amazing:
1. The smallest extension produced without any optimization options!
2. The more optimization options, the less are executables and the greater are shared libs!

I've made memory and performance tests, if You are intersted I can share the results, they are interesting too, but this sizes astonished me.

Regards!

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11518
Re: GCC compiler and linker options
« Reply #7 on: April 21, 2020, 01:20:46 PM »
Hi jazzbiker
... 1. The smallest extension produced without any optimization options! ...
Long answer:
The squashfs is a compressed filesystem. Compression relies on finding repeating sequences of bytes and replacing them with
smaller sequences of bytes. With no optimization, all instructions follow the same path as the source code, and there will be
repetition in the sequences of bytes produced. Optimization tends to remove a lot of that repetition, especially when using the
-Os  flag. If you ever look at the assembly language listing gcc produces, you'll see what at first appears to be very bizarre code.
Things being loaded or jumps being taken for no apparent reason. If you sit down and examine the assembly language listing
carefully, you'll see the gcc maintainers have very clever and sneaky ways of optimizing the code.  In fact, in order to run gdb
on a program, you need to disable optimizations in order to trace the program properly.

Short answer:
Optimizations for size naturally compress an executable. Trying to compress a compressed file results in a larger file.

Offline jazzbiker

  • Hero Member
  • *****
  • Posts: 934
Re: GCC compiler and linker options
« Reply #8 on: April 21, 2020, 04:16:03 PM »
Hi, Rich!

Perhaps, the example of mpg123 is not well suited for compilation options testing, because shared libraries of this package are assembler-optimized for various processors' commands sets, that's why compiler has nothing to do with such a code.

Nevertheless I will post the test results, maybe this will be interesting as some showcase.

Extensions were tested using script:

Code: [Select]
#!/bin/sh

DECODE_LOG="decode.log"
TOP_LOG="top.log"
ROLLUP_LOG="rollup.log"
SMAPS_LOG="smaps.log"

#determining what mpg123 variant is installed
ls -d /tmp/tcloop/mpg123* >> "$DECODE_LOG"
echo >> "$DECODE_LOG"

#testing decode time of certain .mp3 file
time -a -o "$DECODE_LOG" mpg123 -s /tmp/*.mp3 > /dev/null
echo >> "$DECODE_LOG"
echo >> "$DECODE_LOG"

#starting mpg123 in separate terminal
urxvt -e mpg123 /tmp/*.mp3 &

sleep 5

ls -d /tmp/tcloop/mpg123* >> "$TOP_LOG"
echo >> "$TOP_LOG"

#listing brief memory usage
top -m -n 1 | sed -n -e '4p' -e '/urxvt/d' -e '/sed/d' -e '/mpg123/p' >> "$TOP_LOG"
echo >> "$TOP_LOG"
echo >> "$TOP_LOG"

ls -d /tmp/tcloop/mpg123* >> "$ROLLUP_LOG"
echo >> "$ROLLUP_LOG"

cat /proc/"$(pidof mpg123)"/smaps_rollup >> "$ROLLUP_LOG"
echo >> "$ROLLUP_LOG"
echo >> "$ROLLUP_LOG"

ls -d /tmp/tcloop/mpg123* >> "$SMAPS_LOG"
echo >> "$SMAPS_LOG"

cat /proc/"$(pidof mpg123)"/smaps >> "$SMAPS_LOG"
echo >> "$SMAPS_LOG"
echo >> "$SMAPS_LOG"

Times used for certain file decoding are in 'decode.log':
Code: [Select]
/tmp/tcloop/mpg123.1

real 0m 3.73s
user 0m 3.43s
sys 0m 0.29s


/tmp/tcloop/mpg123.2

real 0m 3.77s
user 0m 3.46s
sys 0m 0.29s


/tmp/tcloop/mpg123.3

real 0m 3.76s
user 0m 3.45s
sys 0m 0.29s


/tmp/tcloop/mpg123.4

real 0m 3.72s
user 0m 3.40s
sys 0m 0.31s


/tmp/tcloop/mpg123.5

real 0m 3.76s
user 0m 3.43s
sys 0m 0.30s


/tmp/tcloop/mpg123.6

real 0m 3.75s
user 0m 3.47s
sys 0m 0.26s


/tmp/tcloop/mpg123.7

real 0m 3.80s
user 0m 3.47s
sys 0m 0.31s


/tmp/tcloop/mpg123.8

real 0m 3.79s
user 0m 3.46s
sys 0m 0.31s

and shows almost no difference.

top.log and rollup.log are not informative, so I will skip them.
smaps.log was filtered using:
Code: [Select]
cat smaps.log | grep -A 1 -e 'mpg123' > smaps.filtered.log

and shows the same picture as seen from file sizes:
Code: [Select]
/tmp/tcloop/mpg123.1

08048000-0804b000 r--p 00000000 07:55 4          /tmp/tcloop/mpg123.1/usr/local/bin/mpg123
Size:                 12 kB
--
0804b000-0805e000 r-xp 00003000 07:55 4          /tmp/tcloop/mpg123.1/usr/local/bin/mpg123
Size:                 76 kB
--
0805e000-08065000 r--p 00016000 07:55 4          /tmp/tcloop/mpg123.1/usr/local/bin/mpg123
Size:                 28 kB
--
08065000-08066000 r--p 0001c000 07:55 4          /tmp/tcloop/mpg123.1/usr/local/bin/mpg123
Size:                  4 kB
--
08066000-08068000 rw-p 0001d000 07:55 4          /tmp/tcloop/mpg123.1/usr/local/bin/mpg123
Size:                  8 kB
--
b7f08000-b7f0a000 r--p 00000000 07:55 13         /tmp/tcloop/mpg123.1/usr/local/lib/libout123.so.0.2.2
Size:                  8 kB
--
b7f0a000-b7f12000 r-xp 00002000 07:55 13         /tmp/tcloop/mpg123.1/usr/local/lib/libout123.so.0.2.2
Size:                 32 kB
--
b7f12000-b7f14000 r--p 0000a000 07:55 13         /tmp/tcloop/mpg123.1/usr/local/lib/libout123.so.0.2.2
Size:                  8 kB
--
b7f14000-b7f15000 r--p 0000b000 07:55 13         /tmp/tcloop/mpg123.1/usr/local/lib/libout123.so.0.2.2
Size:                  4 kB
--
b7f15000-b7f16000 rw-p 0000c000 07:55 13         /tmp/tcloop/mpg123.1/usr/local/lib/libout123.so.0.2.2
Size:                  4 kB
--
b7f16000-b7f1a000 r--p 00000000 07:55 9          /tmp/tcloop/mpg123.1/usr/local/lib/libmpg123.so.0.44.10
Size:                 16 kB
--
b7f1a000-b7f5c000 r-xp 00004000 07:55 9          /tmp/tcloop/mpg123.1/usr/local/lib/libmpg123.so.0.44.10
Size:                264 kB
--
b7f5c000-b7f65000 r--p 00046000 07:55 9          /tmp/tcloop/mpg123.1/usr/local/lib/libmpg123.so.0.44.10
Size:                 36 kB
--
b7f65000-b7f66000 r--p 0004e000 07:55 9          /tmp/tcloop/mpg123.1/usr/local/lib/libmpg123.so.0.44.10
Size:                  4 kB
--
b7f66000-b7f67000 rw-p 0004f000 07:55 9          /tmp/tcloop/mpg123.1/usr/local/lib/libmpg123.so.0.44.10
Size:                  4 kB
--
b7f7b000-b7f7c000 r--p 00000000 07:55 15         /tmp/tcloop/mpg123.1/usr/local/lib/mpg123/output_alsa.so
Size:                  4 kB
--
b7f7c000-b7f7d000 r-xp 00001000 07:55 15         /tmp/tcloop/mpg123.1/usr/local/lib/mpg123/output_alsa.so
Size:                  4 kB
--
b7f7d000-b7f7e000 r--p 00002000 07:55 15         /tmp/tcloop/mpg123.1/usr/local/lib/mpg123/output_alsa.so
Size:                  4 kB
--
b7f7e000-b7f7f000 r--p 00002000 07:55 15         /tmp/tcloop/mpg123.1/usr/local/lib/mpg123/output_alsa.so
Size:                  4 kB
--
b7f7f000-b7f80000 rw-p 00003000 07:55 15         /tmp/tcloop/mpg123.1/usr/local/lib/mpg123/output_alsa.so
Size:                  4 kB
--
/tmp/tcloop/mpg123.2

08048000-08065000 rwxp 00000000 07:55 4          /tmp/tcloop/mpg123.2/usr/local/bin/mpg123
Size:                116 kB
--
b7eba000-b7ec5000 rwxp 00000000 07:55 13         /tmp/tcloop/mpg123.2/usr/local/lib/libout123.so.0.2.2
Size:                 44 kB
--
b7ec5000-b7f13000 rwxp 00000000 07:55 9          /tmp/tcloop/mpg123.2/usr/local/lib/libmpg123.so.0.44.10
Size:                312 kB
--
b7f29000-b7f2c000 rwxp 00000000 07:55 15         /tmp/tcloop/mpg123.2/usr/local/lib/mpg123/output_alsa.so
Size:                 12 kB
--
/tmp/tcloop/mpg123.3

08048000-0804b000 r--p 00000000 07:55 4          /tmp/tcloop/mpg123.3/usr/local/bin/mpg123
Size:                 12 kB
--
0804b000-0805d000 r-xp 00003000 07:55 4          /tmp/tcloop/mpg123.3/usr/local/bin/mpg123
Size:                 72 kB
--
0805d000-08064000 r--p 00015000 07:55 4          /tmp/tcloop/mpg123.3/usr/local/bin/mpg123
Size:                 28 kB
--
08064000-08065000 r--p 0001b000 07:55 4          /tmp/tcloop/mpg123.3/usr/local/bin/mpg123
Size:                  4 kB
--
08065000-08066000 rw-p 0001c000 07:55 4          /tmp/tcloop/mpg123.3/usr/local/bin/mpg123
Size:                  4 kB
--
b7e84000-b7e86000 r--p 00000000 07:55 13         /tmp/tcloop/mpg123.3/usr/local/lib/libout123.so.0.2.2
Size:                  8 kB
--
b7e86000-b7e90000 r-xp 00002000 07:55 13         /tmp/tcloop/mpg123.3/usr/local/lib/libout123.so.0.2.2
Size:                 40 kB
--
b7e90000-b7e92000 r--p 0000c000 07:55 13         /tmp/tcloop/mpg123.3/usr/local/lib/libout123.so.0.2.2
Size:                  8 kB
--
b7e92000-b7e93000 r--p 0000d000 07:55 13         /tmp/tcloop/mpg123.3/usr/local/lib/libout123.so.0.2.2
Size:                  4 kB
--
b7e93000-b7e94000 rw-p 0000e000 07:55 13         /tmp/tcloop/mpg123.3/usr/local/lib/libout123.so.0.2.2
Size:                  4 kB
--
b7e94000-b7e97000 r--p 00000000 07:55 9          /tmp/tcloop/mpg123.3/usr/local/lib/libmpg123.so.0.44.10
Size:                 12 kB
--
b7e97000-b7edf000 r-xp 00003000 07:55 9          /tmp/tcloop/mpg123.3/usr/local/lib/libmpg123.so.0.44.10
Size:                288 kB
--
b7edf000-b7ee8000 r--p 0004b000 07:55 9          /tmp/tcloop/mpg123.3/usr/local/lib/libmpg123.so.0.44.10
Size:                 36 kB
--
b7ee8000-b7ee9000 r--p 00053000 07:55 9          /tmp/tcloop/mpg123.3/usr/local/lib/libmpg123.so.0.44.10
Size:                  4 kB
--
b7ee9000-b7eea000 rw-p 00054000 07:55 9          /tmp/tcloop/mpg123.3/usr/local/lib/libmpg123.so.0.44.10
Size:                  4 kB
--
b7efe000-b7eff000 r--p 00000000 07:55 15         /tmp/tcloop/mpg123.3/usr/local/lib/mpg123/output_alsa.so
Size:                  4 kB
--
b7eff000-b7f00000 r-xp 00001000 07:55 15         /tmp/tcloop/mpg123.3/usr/local/lib/mpg123/output_alsa.so
Size:                  4 kB
--
b7f00000-b7f01000 r--p 00002000 07:55 15         /tmp/tcloop/mpg123.3/usr/local/lib/mpg123/output_alsa.so
Size:                  4 kB
--
b7f01000-b7f02000 r--p 00002000 07:55 15         /tmp/tcloop/mpg123.3/usr/local/lib/mpg123/output_alsa.so
Size:                  4 kB
--
b7f02000-b7f03000 rw-p 00003000 07:55 15         /tmp/tcloop/mpg123.3/usr/local/lib/mpg123/output_alsa.so
Size:                  4 kB
--
/tmp/tcloop/mpg123.4

08048000-08063000 rwxp 00000000 07:55 4          /tmp/tcloop/mpg123.4/usr/local/bin/mpg123
Size:                108 kB
--
b7ea1000-b7eae000 rwxp 00000000 07:55 13         /tmp/tcloop/mpg123.4/usr/local/lib/libout123.so.0.2.2
Size:                 52 kB
--
b7eae000-b7f02000 rwxp 00000000 07:55 9          /tmp/tcloop/mpg123.4/usr/local/lib/libmpg123.so.0.44.10
Size:                336 kB
--
b7f19000-b7f1b000 rwxp 00000000 07:55 15         /tmp/tcloop/mpg123.4/usr/local/lib/mpg123/output_alsa.so
Size:                  8 kB
--
/tmp/tcloop/mpg123.5

08048000-0804b000 r--p 00000000 07:55 4          /tmp/tcloop/mpg123.5/usr/local/bin/mpg123
Size:                 12 kB
--
0804b000-0805d000 r-xp 00003000 07:55 4          /tmp/tcloop/mpg123.5/usr/local/bin/mpg123
Size:                 72 kB
--
0805d000-08064000 r--p 00015000 07:55 4          /tmp/tcloop/mpg123.5/usr/local/bin/mpg123
Size:                 28 kB
--
08064000-08065000 r--p 0001b000 07:55 4          /tmp/tcloop/mpg123.5/usr/local/bin/mpg123
Size:                  4 kB
--
08065000-08066000 rw-p 0001c000 07:55 4          /tmp/tcloop/mpg123.5/usr/local/bin/mpg123
Size:                  4 kB
--
b7f23000-b7f25000 r--p 00000000 07:55 13         /tmp/tcloop/mpg123.5/usr/local/lib/libout123.so.0.2.2
Size:                  8 kB
--
b7f25000-b7f2f000 r-xp 00002000 07:55 13         /tmp/tcloop/mpg123.5/usr/local/lib/libout123.so.0.2.2
Size:                 40 kB
--
b7f2f000-b7f31000 r--p 0000c000 07:55 13         /tmp/tcloop/mpg123.5/usr/local/lib/libout123.so.0.2.2
Size:                  8 kB
--
b7f31000-b7f32000 r--p 0000d000 07:55 13         /tmp/tcloop/mpg123.5/usr/local/lib/libout123.so.0.2.2
Size:                  4 kB
--
b7f32000-b7f33000 rw-p 0000e000 07:55 13         /tmp/tcloop/mpg123.5/usr/local/lib/libout123.so.0.2.2
Size:                  4 kB
--
b7f33000-b7f36000 r--p 00000000 07:55 9          /tmp/tcloop/mpg123.5/usr/local/lib/libmpg123.so.0.44.10
Size:                 12 kB
--
b7f36000-b7f7e000 r-xp 00003000 07:55 9          /tmp/tcloop/mpg123.5/usr/local/lib/libmpg123.so.0.44.10
Size:                288 kB
--
b7f7e000-b7f87000 r--p 0004b000 07:55 9          /tmp/tcloop/mpg123.5/usr/local/lib/libmpg123.so.0.44.10
Size:                 36 kB
--
b7f87000-b7f88000 r--p 00053000 07:55 9          /tmp/tcloop/mpg123.5/usr/local/lib/libmpg123.so.0.44.10
Size:                  4 kB
--
b7f88000-b7f89000 rw-p 00054000 07:55 9          /tmp/tcloop/mpg123.5/usr/local/lib/libmpg123.so.0.44.10
Size:                  4 kB
--
b7f9d000-b7f9e000 r--p 00000000 07:55 15         /tmp/tcloop/mpg123.5/usr/local/lib/mpg123/output_alsa.so
Size:                  4 kB
--
b7f9e000-b7f9f000 r-xp 00001000 07:55 15         /tmp/tcloop/mpg123.5/usr/local/lib/mpg123/output_alsa.so
Size:                  4 kB
--
b7f9f000-b7fa0000 r--p 00002000 07:55 15         /tmp/tcloop/mpg123.5/usr/local/lib/mpg123/output_alsa.so
Size:                  4 kB
--
b7fa0000-b7fa1000 r--p 00002000 07:55 15         /tmp/tcloop/mpg123.5/usr/local/lib/mpg123/output_alsa.so
Size:                  4 kB
--
b7fa1000-b7fa2000 rw-p 00003000 07:55 15         /tmp/tcloop/mpg123.5/usr/local/lib/mpg123/output_alsa.so
Size:                  4 kB
--
/tmp/tcloop/mpg123.6

08048000-08063000 rwxp 00000000 07:55 4          /tmp/tcloop/mpg123.6/usr/local/bin/mpg123
Size:                108 kB
--
b7f5d000-b7f6a000 rwxp 00000000 07:55 13         /tmp/tcloop/mpg123.6/usr/local/lib/libout123.so.0.2.2
Size:                 52 kB
--
b7f6a000-b7fbe000 rwxp 00000000 07:55 9          /tmp/tcloop/mpg123.6/usr/local/lib/libmpg123.so.0.44.10
Size:                336 kB
--
b7fd5000-b7fd7000 rwxp 00000000 07:55 15         /tmp/tcloop/mpg123.6/usr/local/lib/mpg123/output_alsa.so
Size:                  8 kB
--
/tmp/tcloop/mpg123.7

08048000-0804b000 r--p 00000000 07:55 4          /tmp/tcloop/mpg123.7/usr/local/bin/mpg123
Size:                 12 kB
--
0804b000-0805c000 r-xp 00003000 07:55 4          /tmp/tcloop/mpg123.7/usr/local/bin/mpg123
Size:                 68 kB
--
0805c000-08063000 r--p 00014000 07:55 4          /tmp/tcloop/mpg123.7/usr/local/bin/mpg123
Size:                 28 kB
--
08063000-08064000 r--p 0001a000 07:55 4          /tmp/tcloop/mpg123.7/usr/local/bin/mpg123
Size:                  4 kB
--
08064000-08065000 rw-p 0001b000 07:55 4          /tmp/tcloop/mpg123.7/usr/local/bin/mpg123
Size:                  4 kB
--
b7efe000-b7f00000 r--p 00000000 07:55 13         /tmp/tcloop/mpg123.7/usr/local/lib/libout123.so.0.2.2
Size:                  8 kB
--
b7f00000-b7f0a000 r-xp 00002000 07:55 13         /tmp/tcloop/mpg123.7/usr/local/lib/libout123.so.0.2.2
Size:                 40 kB
--
b7f0a000-b7f0c000 r--p 0000c000 07:55 13         /tmp/tcloop/mpg123.7/usr/local/lib/libout123.so.0.2.2
Size:                  8 kB
--
b7f0c000-b7f0d000 r--p 0000d000 07:55 13         /tmp/tcloop/mpg123.7/usr/local/lib/libout123.so.0.2.2
Size:                  4 kB
--
b7f0d000-b7f0e000 rw-p 0000e000 07:55 13         /tmp/tcloop/mpg123.7/usr/local/lib/libout123.so.0.2.2
Size:                  4 kB
--
b7f0e000-b7f11000 r--p 00000000 07:55 9          /tmp/tcloop/mpg123.7/usr/local/lib/libmpg123.so.0.44.10
Size:                 12 kB
--
b7f11000-b7f59000 r-xp 00003000 07:55 9          /tmp/tcloop/mpg123.7/usr/local/lib/libmpg123.so.0.44.10
Size:                288 kB
--
b7f59000-b7f62000 r--p 0004b000 07:55 9          /tmp/tcloop/mpg123.7/usr/local/lib/libmpg123.so.0.44.10
Size:                 36 kB
--
b7f62000-b7f63000 r--p 00053000 07:55 9          /tmp/tcloop/mpg123.7/usr/local/lib/libmpg123.so.0.44.10
Size:                  4 kB
--
b7f63000-b7f64000 rw-p 00054000 07:55 9          /tmp/tcloop/mpg123.7/usr/local/lib/libmpg123.so.0.44.10
Size:                  4 kB
--
b7f78000-b7f79000 r--p 00000000 07:55 15         /tmp/tcloop/mpg123.7/usr/local/lib/mpg123/output_alsa.so
Size:                  4 kB
--
b7f79000-b7f7a000 r-xp 00001000 07:55 15         /tmp/tcloop/mpg123.7/usr/local/lib/mpg123/output_alsa.so
Size:                  4 kB
--
b7f7a000-b7f7b000 r--p 00002000 07:55 15         /tmp/tcloop/mpg123.7/usr/local/lib/mpg123/output_alsa.so
Size:                  4 kB
--
b7f7b000-b7f7c000 r--p 00002000 07:55 15         /tmp/tcloop/mpg123.7/usr/local/lib/mpg123/output_alsa.so
Size:                  4 kB
--
b7f7c000-b7f7d000 rw-p 00003000 07:55 15         /tmp/tcloop/mpg123.7/usr/local/lib/mpg123/output_alsa.so
Size:                  4 kB
--
/tmp/tcloop/mpg123.8

08048000-08063000 rwxp 00000000 07:55 4          /tmp/tcloop/mpg123.8/usr/local/bin/mpg123
Size:                108 kB
--
b7f02000-b7f0f000 rwxp 00000000 07:55 13         /tmp/tcloop/mpg123.8/usr/local/lib/libout123.so.0.2.2
Size:                 52 kB
--
b7f0f000-b7f63000 rwxp 00000000 07:55 9          /tmp/tcloop/mpg123.8/usr/local/lib/libmpg123.so.0.44.10
Size:                336 kB
--
b7f7a000-b7f7c000 rwxp 00000000 07:55 15         /tmp/tcloop/mpg123.8/usr/local/lib/mpg123/output_alsa.so
Size:                  8 kB


As You can see memory footprint of the executable itself (mpg123) with accompanied libs (libmpg123, liboutmpg123, output_alsa) is decreased by about 10% if linked with .xbn in one memory segment.

One thing is clear enough - using of .xbn linker script shrinks executables, decreases memory footprint and don't impact compile time and program performance. But resulting code is placed in the same meory segment with 'rwxp' flags, instead of using different segments with appropriate 'r--p' 'rw-p' or 'r-xp' flags. Maybe this is less secure way.

Regards!