bflattened / bflat

C# as you know it but with Go-inspired tooling (small, selfcontained, and native executables)
GNU Affero General Public License v3.0
3.56k stars 102 forks source link

how to pass linker args through --ldflags #96

Open xiaoyuvax opened 1 year ago

xiaoyuvax commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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-baseand -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?!