ld problem

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Dulci
Posts: 17
Joined: Tue Oct 05, 2010 4:34 pm

ld problem

Post by Dulci »

Sorry for having another problem so fast... but hopefully this will be the last one for a while :oops:

So, I'm linking my second stage bootloader with a ld script

Code: Select all

ENTRY(ssblstart)
SECTIONS
{
  .text 0x500 :
  {
    code = .; _code = .; __code = .;
    *(.text)
    . = ALIGN(4096);
  }

  .data :
  {
     data = .; _data = .; __data = .;
     *(.data)
     *(.rodata)
     . = ALIGN(4096);
  }

  .bss :
  {
    bss = .; _bss = .; __bss = .;
    *(.bss)
    . = ALIGN(4096);
  }

  end = .; _end = .; __end = .;
}
which is made with this Makefile

Code: Select all

OBJDIR = ../../build/objects/bootloader
BINDIR = ../../build/bin
CC = gcc
LD=/usr/local/cross/bin/x86_64-elf-ld
ASM = nasm

all: boot

boot: bootstart

bootstart: bootstart.s ssbootloader.s
	@$(ASM) bootstart.s -f bin -o $(BINDIR)/bootstart.img
	@$(ASM) ssbootloader.s -f elf -o $(OBJDIR)/ssbootloader.o
and

Code: Select all

LD=/usr/local/cross/bin/x86_64-elf-ld
SRC=../src

#bootstart.img=512 bytes
#ssbootloader.img=10kilobytes

all: bootloader bin/ssbootloader.img bin/bootstart.img
	@dd if=/dev/zero of=CUBE.iso bs=1024 count=1440 seek=0 skip=0
	@dd conv=notrunc if=bin/bootstart.img of=CUBE.iso
	@dd if=bin/ssbootloader.img of=CUBE.iso seek=1 skip=0 bs=512 count=10 conv=notrunc

bootloader: objects/bootloader/ssbootloader.o $(SRC)/bootloader/ssblinker.ld
	@$(LD) -T $(SRC)/bootloader/ssblinker.ld -o bin/ssbootloader.img objects/bootloader/ssbootloader.o
#-m elf_i386 --oformat=elf32-i386
clean:
	@rm bin/*.img
	@rm CUBE.iso
	@rm objects/bootloader/*.o
The problem is, this was producing the error "/usr/local/cross/bin/x86_64-elf-ld: i386 architecture of input file `objects/bootloader/ssbootloader.o' is incompatible with i386:x86-64 output" I did some checking, and adding

OUTPUT_FORMAT(elf32-i386)
OUTPUT_ARCH(i386)
TARGET(elf32-i386)

to the top of the linker script fixes it. However, it also makes it so the object code produced isn't properly processed into a binary. How would I go about fixing this?
Image
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: ld problem

Post by Combuster »

In other words, GCC Cross-Compiler, Referenced from the FAQ and Getting Started pages for a reason...
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Post Reply