Trouble with LD (unknown option: -T)

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
osdf_1
Posts: 20
Joined: Sun Nov 25, 2007 7:55 pm

Trouble with LD (unknown option: -T)

Post by osdf_1 »

Hi, I'm trying to use a linker script with ld, and I was told that the '-T' option was used to provide one. But when I tried it I got an error saying that the '-T' option doesn't exist. Here's what I did:

>ld -T link.ld -o kernel.bin start.o

And here's what I got:

ld: unknown option: -T

So how can I provide a linker script?
BTW I'm using a Leopard iMac
User avatar
Zenith
Member
Member
Posts: 224
Joined: Tue Apr 10, 2007 4:42 pm

Re: Trouble with LD (unknown oprtion: -T)

Post by Zenith »

Very strange...

First, try doing -Tlink.ld instead of -T link.ld (it might work...). Also check that link.ld actually exists. :wink:

If that doesn't work, do ld --help and see if the -T option is listed. If it isn't, get a different/newer linker.

Then do ld --version and give us the output.

Hope this helps!
"Sufficiently advanced stupidity is indistinguishable from malice."
osdf_1
Posts: 20
Joined: Sun Nov 25, 2007 7:55 pm

Re: Trouble with LD (unknown option: -T)

Post by osdf_1 »

I got:

ld: unknown option: -Tlinker.ld

when using:

> ld -Tlinker.ld -o kernel.bin start.o

and:

ld: unknown option: --version

when using:
> ld --version

I also checked and linker.ld does exist. What should I do?

Oh, and:

>ld -v

outputs:

@(#)PROGRAM:ld PROJECT:ld64-84.3
Last edited by osdf_1 on Sat Jul 19, 2008 9:29 pm, edited 2 times in total.
User avatar
Alboin
Member
Member
Posts: 1466
Joined: Thu Jan 04, 2007 3:29 pm
Location: Noricum and Pannonia

Re: Trouble with LD (unknown option: -T)

Post by Alboin »

Try 'ld -v', and if not, 'man ld'.
C8H10N4O2 | #446691 | Trust the nodes.
osdf_1
Posts: 20
Joined: Sun Nov 25, 2007 7:55 pm

Re: Trouble with LD (unknown option: -T)

Post by osdf_1 »

>ld -v

outputs:

@(#)PROGRAM:ld PROJECT:ld64-84.3

And I couldn't find -T in the man page.
User avatar
Zenith
Member
Member
Posts: 224
Joined: Tue Apr 10, 2007 4:42 pm

Re: Trouble with LD (unknown option: -T)

Post by Zenith »

You're not using GNU ld, you're using something else... I'm assuming this is the linker that came with Leopard? Apple should know better :).

Download and compile the latest GNU binutils, which should have modern, functional copies of ld, as, objdump, and other goodies. They may also have a binary distribution for Mac, if you have trouble with compilation...
"Sufficiently advanced stupidity is indistinguishable from malice."
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Re: Trouble with LD (unknown option: -T)

Post by thepowersgang »

Try using the long version of the script command --script that might work.

If not run

Code: Select all

ld --help
and try to find the script option.
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
osdf_1
Posts: 20
Joined: Sun Nov 25, 2007 7:55 pm

Re: Trouble with LD (unknown option: -T)

Post by osdf_1 »

Well I couldn't install GNU binutils, so I looked up the equivalent for -T, which is -exported_symbols_list (I think). But I think the script file should be written differently. Here's what I did:

> ld -exported_symbols_list linker -arch i386 -o kernel.bin start.o

And I got:

Code: Select all

ld warning: in start.o, file is not of required architecture
Undefined symbols:
  "ENTRY(start)", referenced from:
     -exported_symbols_list command line option
  ".bss : AT(phys + (bss - code))", referenced from:
     -exported_symbols_list command line option
  "code = .;", referenced from:
     -exported_symbols_list command line option
  "end = .;", referenced from:
     -exported_symbols_list command line option
  "OUTPUT_FORMAT("binary")", referenced from:
     -exported_symbols_list command line option
  ".data : AT(phys + (data - code))", referenced from:
     -exported_symbols_list command line option
  "{", referenced from:
     -exported_symbols_list command line option
  "}", referenced from:
     -exported_symbols_list command line option
  ".text phys : AT(phys) {", referenced from:
     -exported_symbols_list command line option
  "bss = .;", referenced from:
     -exported_symbols_list command line option
  "SECTIONS", referenced from:
     -exported_symbols_list command line option
  "data = .;", referenced from:
     -exported_symbols_list command line option
  "phys = 0x00100000;", referenced from:
     -exported_symbols_list command line option
  ". = ALIGN(4096);", referenced from:
     -exported_symbols_list command line option
ld: symbol(s) not found
Here's my script, anyone knows what would be Apple ld's equivalent?

Code: Select all

OUTPUT_FORMAT("binary")
ENTRY(start)
phys = 0x00100000;
SECTIONS
{
  .text phys : AT(phys) {
    code = .;
    *(.text)
    *(.rodata)
    . = ALIGN(4096);
  }
  .data : AT(phys + (data - code))
  {
    data = .;
    *(.data)
    . = ALIGN(4096);
  }
  .bss : AT(phys + (bss - code))
  {
    bss = .;
    *(.bss)
    . = ALIGN(4096);
  }
  end = .;
}
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: Trouble with LD (unknown option: -T)

Post by JamesM »

Apple use their own toolchain that only has loose compatibility with the GNU tools. Given the bug I found in their assembler's lexer the other week I wouldn't trust that toolchain as far as I could throw it.

You can get the GNU tools at ftp://ftp.gnu.org.
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: Trouble with LD (unknown option: -T)

Post by Combuster »

Or preferrably, GCC Cross-Compiler
"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