Compiling C on AARCHIE

c programming banner


The purpose of this lab is to investigate basic C source code and analyze elf64-littleaarch64 files created by the gcc compiler.

To demonstrate the differences I created a simple hello world program in C and compiled it on an Seneca’s AARCH64 system “aarchie”.

#include <stdio.h>
int main() {
printf(“Hello World!\n”);

// -g # enable debugging information
// -O0 # do not optimize (that’s a capital letter and then the digit zero)
// -fno-builtin # do not use builtin function optimizations
//compile command
gcc -g -o0 -fno-builtin -o hello-0 hello.c

Running the Test

Follow the instructions/commands bellow to run this test on your own system:

  1. Download and unzip
  2. Change to the “lab2” directory
    cd lab2
  3. Compiles “hello-0.c” – “hello-6.c” using different compile flags for each.
  4. Executes all the compiled hello-# programs, and export the results of  “objdump” to a text file.
    make run



For each test, I’ve created a link to a file diff page for each objdump that will highlight the changes made. Each test was compared to the original hello.c file, using the compiler noted above.

(1) Add the compiler option -static.

hello-0_objdump.txt <-> hello-1_objdump.txt

//-static option links a program statically, and does not require a dynamic libraries at run time
//compile command
$gcc -g -O0 -fno-builtin -static -o hello-1 hello.c

The programs uses the static version of the C library opposed to dynamic libraries.
File Size
hello-1: 815kb

(2) Removed the compiler option -fno-builtin.

hello-0_objdump.txt <-> hello-2_objdump.txt

//compile command
$gcc -g -O0 -o hello-2 hello.c

(3) Removed the compiler option -g. Note and explain the change in size, section headers, and disassembly output.

hello-0_objdump.txt <-> hello-3_objdump.txt

//compile command
$gcc -O0 -fno-builtin -o hello-3 hello.c

The debug header was completely removed resulting in a smaller file size.

(4) Add additional arguments to the printf() function in your program. Note which register each argument is placed in.

hello-0_objdump.txt <-> hello-4_objdump.txt

#include &lt;stdio.h&gt;
int main() {
printf(&#8220;Hello %s%c %d \n&#8221;,&#8221;world&#8221;,&#8217;!&#8217;, 2017 );

//compile command
$gcc -g -O0 -fno-builtin -o hello-4 hello-4.c

(5) A separate function named output() was created with printf(). call to a separate function named output(), and call that function from main().

hello-0_objdump.txt <-> hello-5_objdump.txt

#include &lt;stdio.h&gt;
void output(){
printf(&#8220;Hello World!\n&#8221;);
int main() {

//compile command
$gcc -g -O0 -fno-builtin -o hello-5 hello-5.c

(6) Removed -O0 and added -O3 to the gcc options. Note and explain the difference in the compiled code.

hello-0_objdump.txt <-> hello-6_objdump.txt

//compile command
$gcc -g -O3 -fno-builtin -o hello-6 hello.c

Related Posts