Page 1 of 1

A problem of linking.

Posted: Fri Nov 06, 2015 11:49 pm
by 626788149
When I type these commands.
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
Why Offset at 0x200020?

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 = .);
}
entry.S

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
libmain.c

Code: Select all

extern void umain(int argc, char **argv);
void
libmain(int argc, char **argv)
{
	umain(argc, argv);
}
test.c

Code: Select all

void umain()
{
//nothing

}

Re: A problem of linking.

Posted: Sat Nov 07, 2015 6:19 am
by Combuster
Posting Checklist, first item.