This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
ld --gc-sections for libraries, gcc generating movsl
- To: <binutils at sources dot redhat dot com>
- Subject: ld --gc-sections for libraries, gcc generating movsl
- From: Etienne Lorrain <etienne at masroudeau dot com>
- Date: Mon, 8 Jan 2001 01:09:33 -0800 (PST)
Hello,
I just have a question and a (small) request of feature if someone
had time.
This is related to the development of the Gujin bootloader, at:
http://sourceforge.net/projects/gujin/
Source download at:
http://sourceforge.net/project/showfiles.php?group_id=15465&release_id=18235
I am using binutils-2.10.1 and gcc-2.95.2/gcc-2.95.3-pre1, it does
not seem to be version dependant.
The question is why only some unused functions are removed using
"gcc -ffunction-sections" and "ld --gc-sections". It seems that
all function not called and not removed are in the two libraries
(ext2fs and zlib) I am using.
To show the problem, you need to build the complete Gujin with or
without the Makefile variable "GC_SECTION".
Lets say you have downloaded in a directory the 3 files:
(from ftp://ftp.freesoftware.com/pub/linux/tsx-11/packages/ext2fs/)
e2fsprogs-1.19.tar.gz
(from ftp://ftp.freesoftware.com/pub/infozip/zlib/)
zlib-1.1.3.tar.gz
(from http://sourceforge.net/project/gujin)
gujin-0.2.tar.gz
then type:
tar -xzf gujin-0.2.tar.gz
cd gujin
make proper dep boot.exe
You get at the end the size of different area of memory:
grep "__sizeof_" boot.map | sed 's/ / /g;s/0x0000/0x/;s/=.*//'
0xdca4 __sizeof_gujin_code_in_text
0x4993 __sizeof_gujin_code_in_extra
0x5738 __sizeof_e2fs_code_in_extra
0x3b91 __sizeof_zlib_code_in_extra
0x0220 __sizeof_inter_section_code
0x0001bb20 __sizeof_all_code
This build is automatically patching the libraries with the two files
"nogce2fs.pch" and "nogczlib.pch", these patch just removes the unused
functions. For instance, the function "get_crc_table()" is removed
from file "zlib-1.1.3/crc32.c" because I know it is not used.
Now try to rebuild after uncommenting (removing the #) of line
167 of Makefile (#SETUP+=|GC_SECTION):
vi +167 Makefile
make proper dep boot.exe # rebuild also libraries
I get:
grep "__sizeof_" boot.map | sed 's/ / /g;s/0x0000/0x/;s/=.*//'
0xdc9c __sizeof_gujin_code_in_text
0x4993 __sizeof_gujin_code_in_extra
0x6a92 __sizeof_e2fs_code_in_extra
0x402f __sizeof_zlib_code_in_extra
0x0210 __sizeof_inter_section_code
0x0001d300 __sizeof_all_code
This build does _not_ use the files nogce2fs.pch and nogczlib.pch.
Size of the code in segment "extra" has increased from 0x5738
to 0x6a92, and we can check that get_crc_table() is defined but
not used:
grep -2 get_crc_table boot.map
.text.adler32 0x0000b428 0x1ba libz.a(adler32.o)
0x0000b428 adler32
.text.get_crc_table
0x0000b5e2 0x8 libz.a(crc32.o)
0x0000b5e2 get_crc_table
.text.crc32 0x0000b5ea 0x110 libz.a(crc32.o)
0x0000b5ea crc32
--
general_protection boot.o
library.o
get_crc_table libz.a(crc32.o)
gujin_param boot.o
main.o
But the work was correctly done for my "text" segment with its
size decreasing from 0xdca4 to 0xdc9c. (libraries are all loaded
in segment extra)
If someone has a clue of what I am doing wrong, I am very interrested.
---------------
The small request is linked to my ".code16gcc", and due to the
fact that GCC is sometimes generating "movs[bwl]" or "stos[bwl]",
but unqualified concerning the adress size: %es:(%di) or %es:(%edi).
Depending on some configurations of Gujin, I would like to
have either of these by default, controlled by a configuration
switch. In a perfect world:
.code16,stack32,strops16 # equivalent to current .code16gcc
.code16,stack16 # equivalent to current .code16
.code16,stack32,strops32 # my config when BIG_MALLOC
Right now, everything is working because I am using these
macros (in libincl.h):
.macro movsl src=%ds:(%esi), dst=%es:(%edi)
.byte 0x67, 0x66, 0xA5 # movs.l %ds:(%esi),%es:(%edi)
.endm
But it is not really clean, and also such macro is not
expended when appearing after a semicolon (bug or feature?),
so:
asm (" std ; movsl "); -> uses 16 bit destination
asm (" std \n movsl "); -> uses 32 bit destination
If someone had time to write this to the "would be nice"
book...
Thanks for reading,
Etienne.