Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to pass linker args through --ldflags #96

Open
xiaoyuvax opened this issue Mar 16, 2023 · 2 comments
Open

how to pass linker args through --ldflags #96

xiaoyuvax opened this issue Mar 16, 2023 · 2 comments

Comments

@xiaoyuvax
Copy link

xiaoyuvax commented Mar 16, 2023

i need to pass these args -r --image-base=0x10000000 to LLD,
seems no way to work with --ldflags.
need some escaping brackets to make sure these linker args will not be processed by bflat.

@MichalStrehovsky
Copy link
Member

Does --ldflags "-r --image-base=0x10000000" not work?

You can always pass -x: this will tell you how bflat invokes the linker. Then remove -x and pass -c. This will compile, but not link, leaving you with an object file you can link yourself.

@xiaoyuvax
Copy link
Author

xiaoyuvax commented Mar 17, 2023

not for path with spaces. (...turns out to be, when i separate the args with the path and pls note this is in RSP)
e.g.:

-x
--ldflags "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.35.32215\lib\x64\oldnames.lib"
--ldflags "--image-base=0x10000000 -map=kernel.map"

output:

- Executing building script: bflat build @build.rsp...
D:\bflat\bin\lld.exe -flavor link "MOOS.obj" /out:"MOOS.exe" /libpath:"D:\bflat\lib\windows\x64" /libpath:"D:\bflat\lib\windows" /libpath:"D:\bflat\lib" /subsystem:console /entry:__managed__Main /incremental:no /debug /merge:.modules=.rdata sokol.lib advapi32.lib bcrypt.lib crypt32.lib iphlpapi.lib kernel32.lib mswsock.lib ncrypt.lib normaliz.lib  ntdll.lib ole32.lib oleaut32.lib user32.lib version.lib ws2_32.lib shell32.lib Secur32.Lib /opt:ref,icf /nodefaultlib:libcpmt.lib d:\repos\moos\x64\Debug\Doom.lib d:\repos\moos\x64\Debug\LibC.lib d:\repos\moos\x64\Debug\NativeLib.lib C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.35.32215\lib\x64\oldnames.lib --image-base=0x10000000 -map=kernel.map
lld: warning: ignoring unknown argument '--image-base=0x10000000'
lld: warning: ignoring unknown argument '-map=kernel.map'
lld: error: could not open 'C:\Program': No such file or directory
lld: error: could not open 'Files\Microsoft': No such file or directory
lld: error: could not open 'Visual': No such file or directory
lld: error: could not open 'Studio\2022\Enterprise\VC\Tools\MSVC\14.35.32215\lib\x64\oldnames.lib': No such file or directory
lld: error: could not open 'OLDNAMES.lib': No such file or directory
Compiler exit code:1

seems no way to pass the quotes to lld through bflat, not even with double quotes at both ends of the path, still need certain escaping contract, e.g. use "'{path}'" in bflat results in "{path}" for lld.

also it's weird that lld doesn't support --image-base and -map ?!

update:

  1. Can only be solved by manully linking by spliting the <libfilepath> to /libpath:"" <libfilename>
    directly specify path to a lib file with spaces and quotes does not work for the linker.

  2. turns out lld.exe in bflat is actually MSVC linker! so the linker args should be in style like /base:0x10000000, but don't know why it doesn't support /map:kernel.map anyway?!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants