I follow the wiki on GCC Cross Compiler and get myself a working GCC cross compiler until I tried to build some shared libraries.
For a very simple code:
ml_main.h
Code: Select all
#ifndef _ml_main_h_
#define _ml_main_h_
int ml_func(int a, int b);
#endif
Code: Select all
#include "ml_main.h"
int myglob = 42;
int ml_func(int a, int b) {
myglob += a;
return b + myglob;
}
Code: Select all
i686-elf-gcc -c -std=c11 -Wall -Wextra -Werror -masm=intel -g -O0 -fPIC -ffreestanding ml_main.c -o ml_main.o
Code: Select all
i686-elf-gcc -o mymodule.so -O0 -nostdlib -shared -fPIC -Wl,-soname,mymodule.so -ffreestanding ml_main.o
Code: Select all
/home/xxxxxx/opt/cross/lib/gcc/i686-elf/7.2.0/../../../../i686-elf/bin/ld: warning: cannot find entry symbol _start; defaulting to 0000000008048074
Code: Select all
ELF Header:
Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: EXEC (Executable file)
Machine: Intel 80386
Version: 0x1
Entry point address: 0x8048074
Start of program headers: 52 (bytes into file)
Start of section headers: 2720 (bytes into file)
Flags: 0x0
Size of this header: 52 (bytes)
Size of program headers: 32 (bytes)
Number of program headers: 2
Size of section headers: 40 (bytes)
Number of section headers: 15
Section header string table index: 14
Code: Select all
ELF Header:
Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
Class: ELF64
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: DYN (Shared object file)
Machine: Advanced Micro Devices X86-64
Version: 0x1
Entry point address: 0x390
Start of program headers: 64 (bytes into file)
Start of section headers: 6928 (bytes into file)
Flags: 0x0
Size of this header: 64 (bytes)
Size of program headers: 56 (bytes)
Number of program headers: 7
Size of section headers: 64 (bytes)
Number of section headers: 25
Section header string table index: 24