Hi Arun, thanks for letting us know about this. Would you mind creating a bug on Jira? https://gem5.atlassian.net/jira/software/c/projects/GEM5/issues
I'll have to look at this more closely, but I think this is a bug in the CheckLinkFlag check, where it should not set SHLINKFLAGS even if set_for_shared is enabled if ret is False. I don't think we want to disable set_for_shared, even though in this case it has the effect of also disabling that "if", which compensates for the fact that it's not checking ret. Like I said I'll look at the history of this code to see if I'm missing something, but I think working "ret" into the check for SHLINKFLAGS is probably what the fix should be. Could you try that? And if that works for you, would you mind uploading a fix? https://www.gem5.org/contributing Please add me as a reviewer if you do. Gabe On Thu, Nov 18, 2021 at 3:53 PM Rodrigues, Arun F via gem5-dev < gem5-dev@gem5.org> wrote: > 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 -- gem5-dev@gem5.org > To unsubscribe send an email to gem5-dev-le...@gem5.org > %(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s
_______________________________________________ gem5-dev mailing list -- gem5-dev@gem5.org To unsubscribe send an email to gem5-dev-le...@gem5.org %(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s