1

Hi All I have been trying to link my assembly code to a C++ file so I can fall my function kMain from assembly and When I link it with this script :

ENTRY(_Start)
SECTIONS
{
    . = 0x2000;

    .text : AT(ADDR(.text) - 0x2000)
    {
        _code = .;
        *(.text)
        *(.rodata*)
        . = ALIGN(4096);
    }

   .data : AT(ADDR(.data) - 0x2000)
   {
        _data = .;
        *(.data)
        . = ALIGN(4096);
   }

   .eh_frame : AT(ADDR(.eh_frame) - 0x2000)
   {
       _ehframe = .;
       *(.eh_frame)
        . = ALIGN(4096);
   }

   .bss : AT(ADDR(.bss) - 0x2000)
   {
       _bss = .;
       *(.bss)

       /*
        * You usually need to include generated COMMON symbols
        * under kernel BSS section or use gcc's -fno-common
        */

        *(COMMON)
       . = ALIGN(4096);
   }

   _end = .;

   /DISCARD/ :
   {
        *(.comment)
   }
}

I get a warning saying : x86_64-elf-ld: warning: cannot find entry symbol _Start; defaulting to 0000000000002000 But in my Assembly Code I have this at the start:

[BITS 16] 
_Start: 

Any Ideas as to why its not linking Correctly?? EDIT: It works now With this declared:

global _Start:
_Start:

But It won't load the program at the adress 0x2000 I use a batch program to compile/assemble, format and link my OS here it is:

nasm Stage1.asm -o Stage1.bin
nasm -f elf64 Stage2.asm -o Stage2.o
x86_64-elf-g++ -ffreestanding -mcmodel=large -mno-red-zone -mno-mmx -mno-sse -mno-sse2 -mno-sse3 -mno-3dnow -c -o kernel.o kernel.cpp
x86_64-elf-ld -T linkerscript.ld -o MyOS.bin Stage2.o kernel.o -nostdlib
copy Stage1.bin Root
copy MyOS.bin Root
mkisofs -b Stage1.bin -no-emul-boot -boot-info-table -o BootLoader.iso ./Root

If you wan't to see all of the source code it is here: https://github.com/AnonymousUser1337/Anmu

AnonymousUser
  • 109
  • 1
  • 12
  • You might have to declare the _Start label as global using some kind of assembler directive (e.g. "global"?). Your question is missing TONS of important details like what you're trying to accomplish and what tools you are using and how you are invoking them. – David Grayson Aug 11 '14 at 01:19
  • Ya the global worked I but it's not setting the origin of the file to 0x2000 – AnonymousUser Aug 11 '14 at 01:33
  • @DavidGrayson Does the Edit help?? – AnonymousUser Aug 11 '14 at 02:54
  • Since my comment solved the original problem, I would consider this question to be answered. You should ask a new question where you are again very specific about what you are doing, but you also need to be very specific about what is going wrong. What does "It won't load the program at the adress 0x2000" actually mean in terms of what you see on the screen with your eyes? – David Grayson Aug 12 '14 at 02:41
  • @DavidGrayson Ok I followed your advice and made a new question if you could help that would be great :D Sorry about not describing my problem enough in detail this new question has a lot more detail than this one: http://stackoverflow.com/questions/25255748/linker-script-not-settting-the-origin-correctly – AnonymousUser Aug 12 '14 at 03:38

1 Answers1

2

You probably have to declare the _Start label as global using some kind of assembler directive (e.g. global).

David Grayson
  • 84,103
  • 24
  • 152
  • 189