1

I am trying to send the linker scripts for one of the simple c program . I tried on both on Ubuntu and Windows.

On Ubuntu

After some research I found out that it was taking GNU-ld ,so With clang command line option -fuse-ld=lld ,So now I linked with clang default linker lld

I tried with this command

clang main.c -ffreestanding -nostartfiles -nodefaultlibs -fuse-ld=lld -Wl,-Map,output.map,-T Example_Linker.ld -o main

Everything works correctly. I got the memory map file and also able to pass linker scripts.

On Windows

Clang initially look for Microsoft Visual Studio Linker link.exe for to generate executables.

It wont support Linker scripts.

So with -fuse-ld=lld

I tried the below command
clang main.c -ffreestanding -nostartfiles -nodefaultlibs -fuse-ld=lld -Wl,-Map,output.map,-T Example_Linker.ld -o main

So now error thrown was

clang: error: unknown argument: '-Map'
lld-link: warning: ignoring unknown argument: -T

How should I write a command so I may be able to get a memory map file and in same time I can pass Linker Scripts?

kindly help me with solution.

Jon marsh
  • 279
  • 7
  • 12
  • I am not familiar with development on Windows, but on Mac, you pass `-map` instead of `-Map`, maybe the same will work for Windows? Not sure about the linker scripts, though. – AlexDenisov Aug 07 '19 at 09:00
  • yes when I gave -map it will give map file. But when i linked with llvm linker ```lld``` nothing seems to be working.I will get the above error. – Jon marsh Aug 07 '19 at 10:35

2 Answers2

2

The linker flags you write here:

    -Wl,-Map,output.map

should be

    -Wl,-Map=output.map
smsxgli
  • 31
  • 5
0

You have to use the same target triple as on Ubuntu.

On my Ubuntu clang outputs this information:

$ clang-8 --version
clang version 8.0.0-3~ubuntu18.04.2 (tags/RELEASE_800/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

So you would use the following on windows:

clang --target=x86_64-pc-linux-gnu main.c -ffreestanding -nostartfiles -nodefaultlibs -fuse-ld=lld -Wl,-Map=output.map,-T Example_Linker.ld -o main

I cannot try this, because I don't have a linker script. You can try to change the target triple.

Ole
  • 56
  • 4