Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22159

How to remove 'bloat' from a compiled shared object?

$
0
0

I have a gcc C application which compiles to a shared object using the -fpicoption. The intent is to create a 'executable' which allows running the code anywhere in the memory.This is how a sample C program is compiled.

./armeb-eabi-gcc -march=armv5t -mbig-endian -nostdlib  -fpic   -c  main.c

main.c

 int main(){    void (*UART)() = 0x594323 | 1;    UART("Hello");}

The problem is the compiled executable has 'bloat' where i am only looking for machine code and no symbols. I was unable to extract the exact portions from objcopy and objdump which did absolutely nothing. The file size is around 948 bytes which is insane for such simple program.

Here is a snippet of the 'portion' of the file i am looking for.hex dump of main.o

(The exact highlighted parts could be skewed)


Running

objcopy -I elf32-big -O binary main.o test.bin

gives a 64 byte file which for some odd reason moves part of the string to the top of the file which makes tools like ghidra and ida unable to disassemble properly. hex dump of the sanitized fileenter image description here

Hopefully it can be seen that the reference to "Hello" is incorrect.


Viewing all articles
Browse latest Browse all 22159

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>