Question
C program. Problem 1 miniature ELF-compliant Hello, world! Purpose: to explore the low-level details of C library, tool chain, and program loading interface by trying
C program.
Problem 1 miniature ELF-compliant Hello, world!
Purpose: to explore the low-level details of C library, tool chain, and program loading interface by trying to reduce the size of an executable file.
Your task is to come up with the smallest executable binary which prints out Hello, world! to the standard output without an error. Note that were trying to minimize size of the executable of a very simple program so you need to focus on shedding weight in other areas.
The rules: - The resulting binary must be ELF-compliant 64-bit x86 executable. It should end its execution correctly, meaning that it must exit with error code 0 (zero). These conditions can be tested using readelf and file commands and checking the error code in shell by echo $? after execution.
- You should use C file as the source. You can use assembly if you wish, but I wont be impressed if it doesnt yield a significant size reduction, or it produces a broken ELF executable.
On cardiac, without any proactive size reduction, you will get a binary with around 8KB in size. With some efforts, you can obtain a binary less than 1KB.
Among binutils, readelf and strip are the tools you probably have to use to identify problems and reduce size. objdump may be helpful too. Check the man pages of these tools for details.
Here are some additional pointers/hints:
- Use system call directly instead of printf() C library routine. You should check man pages for syscall, syscalls. (The SYS_xxx symbols can be found in /usr/include/bits/syscall.h )
- main() can be eliminated the actual entry point that low-level ABI uses is the _start symbol. You can implement _start() instead of main(), thereby avoiding C runtime. Note that now it has become your responsibility to exit the program with a return value. Check the man page for exit().
- Once you do the above, you may not need to link the C runtime library. nostdlib option of gcc allows you to do that. But! you may still need to statically link C library for syscall wrappers. Static C library is called libc.a. In cardiac, it is located at /usr/lib/x86_64- redhat-linux6E/lib64/libc.a
- By default, gcc adds bunch of debug symbols to an executable. These are needed for debugging the program, so you dont need them for running it. You can strip these away.
- Additional examination of the file may reveal that there are some boilerplate sections in the ELF executable. Some of them can be safely removed without hurting the functionality.
What to turn in:
- Your source code named prob1_.c
- Your final binary named prob1_
- Makefile or a shell script that performs the size-reducing operations that you developed. It must produce the final binary from your source code. This file must contain step-bystep comments that explain why each step is needed.
Thank you for helpping.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started