I get a executable file test.
But this file is to big,about 2MB.
Why?
Code: Select all
cc -c -m32 entry.S libmain.c test.c
ar -r libOS.a entry.o libmain.o
ld -o test -T user.ld t.o -L. -lOS
Code: Select all
程序头:
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
LOAD 0x200020 0xf0000020 0xf0000020 0x00088 0x00088 R E 0x200000
GNU_STACK 0x000000 0x00000000 0x00000000 0x00000 0x00000 RWE 0x10
user.ld
Code: Select all
OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386")
OUTPUT_ARCH(i386)
ENTRY(_start)
SECTIONS
{
/* Load programs at this address: "." means the current address */
. = 0xf0000020;
.text : {
*(.text .stub .text.* .gnu.linkonce.t.*)
}
PROVIDE(etext = .); /* Define the 'etext' symbol to this value */
.rodata : {
*(.rodata .rodata.* .gnu.linkonce.r.*)
}
/* Adjust the address for the data segment to the next page */
. = ALIGN(0x1000);
.data : {
*(.data)
}
PROVIDE(edata = .);
.bss : {
*(.bss)
}
PROVIDE(end = .);
}
Code: Select all
.text
.globl _start
_start:
// See if we were started with arguments on the stack
jne args_exist
// If not, push dummy argc/argv arguments.
// This happens when we are loaded by the kernel,
// because the kernel does not know about passing arguments.
pushl $0
pushl $0
args_exist:
call libmain
1: jmp 1
.data
Code: Select all
extern void umain(int argc, char **argv);
void
libmain(int argc, char **argv)
{
umain(argc, argv);
}
Code: Select all
void umain()
{
//nothing
}