Hello,
I’m running into some issues building libgem5 on MacOS using clang. The build
compiles correctly, but fails during linking because the LLVM linker doesn’t
understand the –as-needed flag. It seems that gem5 is incorrectly passing this
flag.
Buildline:
scons build/RISCV/libgem5_opt.dylib -j 8 --without-tcmalloc
Failure:
[ SHLINK] -> RISCV/libgem5_opt.dylib
ld: unknown option: --as-needed
clang: error: linker command failed with exit code 1 (use -v to see invocation)
scons: *** [build/RISCV/libgem5_opt.dylib] Error 1
The toplevel SConstruct file, line 343 has:
conf.CheckLinkFlag('-Wl,--as-needed')
On MacOS with clang, this check returns ‘no’ since the clang linker doesn’t
take the –as-needed flag. But, it seems that CheckLinkFlag()’s default behavior
(set_for_shared=True) seems to be to append the flag, even if the config test
fails.
Configure.py:
def CheckLinkFlag(context, flag, autoadd=True, set_for_shared=True):
context.Message("Checking for linker %s support... " % flag)
last_linkflags = context.env['LINKFLAGS']
context.env.Append(LINKFLAGS=[flag])
ret = context.TryLink('int main(int, char *[]) { return 0; }', '.cc')
if not (ret and autoadd):
context.env['LINKFLAGS'] = last_linkflags
if set_for_shared:
assert(autoadd)
context.env.Append(SHLINKFLAGS=[flag])
context.Result(ret)
return ret
This results in the linking phase failing on MacOS.
I was able to get it to build by changing the toplevel SConstruct to:
conf.CheckLinkFlag('-Wl,--as-needed', True, False)
I’m not too familiar with the –as-needed flag and why it is needed, so I’m
wondering:
* Does this fix seem reasonable?
* Is the CheckLinkFlag() behavior correct? Should the flag be appended to
SHLINKFLAGS even if the test fails?
Additional info:
* Clang/clang++ Apple clang version 11.0.0 (clang-1100.0.33.17)
* Uname -a: Darwin s1033894 19.6.0 Darwin Kernel Version 19.6.0: Sun Jul 5
00:43:10 PDT 2020; root:xnu-6153.141.1~9/RELEASE_X86_64 x86_64
Thanks,
arun
Thanks,
arun
_______________________________________________
gem5-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s