bug-binutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How create small binaries with GNU binutils.


From: Dmitry Bogatov
Subject: How create small binaries with GNU binutils.
Date: Fri, 01 Feb 2019 14:27:03 +0000

[ Not a but, strictly speaking, but just do not know, where else to ask. ]

Hello!

I like AT&T syntax of amd64 assembler, so I am using GNU As.
Unfortunately, it creates binries much bigger then one would expect from
source code.  For compraison, trivial program, that just exits with
value 1 (essentially, /bin/false), implemented in fasm:

        ;; a02.fasm
        format ELF64 executable at 0000000100000000h

        segment readable executable

        entry $
                xor edi,edi
                inc edi
                mov eax,60
                syscall

complied in following way

    $ fasm a02.fasm
    flat assembler  version 1.73.06  (16384 kilobytes memory)
    1 passes, 131 bytes.

results in tiny binary.

Equivalent program, compiled and linked with binutils

        # a01.S
        .globl _start
        _start:
                xor %di, %di
                inc %di
                mov $60, %eax
                syscall

with following commands:

        as a01.S -o a01.o
        ld a01.o

results in huge binary:

        $ du -hb a.out
        4744    a.out
        $ strip -s a.out
        $ du -hb a.out
        4408    a.out
        $ file a.out
        a.out: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically 
linked, stripped

Both `as` and `ld` are from Debian package `binutils=2.31.1-11`.  What
am I doing wrong? Can I force binutils to create small, ~150 bytes
binary?
-- 
        Note, that I send and fetch email in batch, once every 24 hours.
                 If matter is urgent, try https://t.me/kaction
                                                                             --

Attachment: pgpavann2yMNj.pgp
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]