Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 30 May 2020 17:45:15 -0700
From:      John-Mark Gurney <jmg@funkthat.com>
To:        Jack Raats <mlist@nlned.nl>
Cc:        freebsd-arm@freebsd.org
Subject:   Re: code generation
Message-ID:  <20200531004515.GU4213@funkthat.com>
In-Reply-To: <7aed18ab40ff22810b64bbb77b481c78.squirrel@www.nlned.nl>
References:  <7aed18ab40ff22810b64bbb77b481c78.squirrel@www.nlned.nl>

next in thread | previous in thread | raw e-mail | index | archive | help
Jack Raats wrote this message on Sat, May 30, 2020 at 23:52 +0200:
> Hi,
> 
> Can anyone explain why a simple hello_world.c compiles on a AMD64 machine
> to +/- 21000 bytes while on a raspberry pi 3 +/- 206000 bytes (10 times
> more)
> 
> I use FreeBSD 12.1 stable on RPi3 and cc -o hello hello.c to compile.

What file, and what's your compiler options.  This is on 13-current,
but shouldn't be dramatically different.  it's on a Pine64 A64-LTS,
but that shouldn't mater either.

freebsd@generic:~ $ cat hello.c
#include <stdio.h>

int
main(void)
{

	printf("hello world\n");

	return 0;
}
freebsd@generic:~ $ cc -o hello hello.c
freebsd@generic:~ $ ls -l hello
-rwxr-xr-x  1 freebsd  freebsd  14232 Jan  1 16:14 hello
freebsd@generic:~ $ ./hello
hello world

This is even smaller when you strip it:
freebsd@generic:~ $ strip hello
freebsd@generic:~ $ file hello
hello: ELF 64-bit LSB executable, ARM aarch64, version 1 (FreeBSD), dynamically linked, interpreter /libexec/ld-elf.so.1, for FreeBSD 13.0 (1300094), FreeBSD-style, stripped
freebsd@generic:~ $ ls -l hello
-rwxr-xr-x  1 freebsd  freebsd  5456 Jan  1 16:19 hello

Though on the other hand, compile it static and:
freebsd@generic:~ $ cc -o hello hello.c -static -O2
freebsd@generic:~ $ ls -l hello
-rwxr-xr-x  1 freebsd  freebsd  4229680 Jan  1 16:14 hello

4MB seems a bit huge for a statically compiled program...

But that's because of debug symbols:
freebsd@generic:~ $ cc -o hello hello.c -static -O2
freebsd@generic:~ $ file hello
hello: ELF 64-bit LSB executable, ARM aarch64, version 1 (FreeBSD), statically linked, for FreeBSD 13.0 (1300094), FreeBSD-style, with debug_info, not stripped
freebsd@generic:~ $ strip hello
freebsd@generic:~ $ ls -l hello
-rwxr-xr-x  1 freebsd  freebsd  701808 Jan  1 16:17 hello

But even stripped, it's still VERY large...

-- 
  John-Mark Gurney				Voice: +1 415 225 5579

     "All that I will do, has been done, All that I have, has not."



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20200531004515.GU4213>