Reputation: 339
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.
Upvotes: 2
Views: 5491
Reputation: 98
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.
Upvotes: 1
Reputation: 41
The linker flags you write here:
-Wl,-Map,output.map
should be
-Wl,-Map=output.map
Upvotes: 3