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

Feature request: Allow any compatible compiler to be used, not just compilers from the hard-coded list #20075

Open
simonhf opened this issue Jul 23, 2022 · 4 comments
Labels

Comments

@simonhf
Copy link

simonhf commented Jul 23, 2022

Summary

Currently only a few named compilers can be specified on the Nim command line, and if they are not on the hard-coded list of all compilers then an error will occur, e.g. using --cc:foo. It would be great if there was a new command line option -- e.g. --forceCC:on|off -- which allows any compatible compiler to be used even if it's not on the hard-coded list, e.g. using --cc:foo --forceCC:on.

Description

So Nim can compile to C. So I tried to run cwrap [1] with Nim. cwrap works by pretending to be gcc (so Nim thinks it is just compiling as usual...!) and then using special gcc features to discover all the functions during compilation, and then create all the code necessary to instrument all those functions. Each instrumented function then has its own unique verbosity level which can be set dynamically at runtime. FYI it was possible to get the two working together and I posted instructions for an example Nim hello world program instrumented with cwrap here [2]. The only issue was the hard-coded list of compilers which needed a hacky workaround...

[1] https://github.com/corelight/cwrap
[2] corelight/cwrap#2

Alternatives

n/a

Additional Information

n/a

@Yardanico
Copy link
Collaborator

Yardanico commented Jul 23, 2022

If your C compiler is GCC-compatible, you can just do --gcc.exe:"mycompiler" (--gcc.exe:"cwrap" in your case), no need for hacky workarounds :)

Also, if you want to reduce the "noisiness" from instrumentation, it might be worth to compile in release mode with -d:release (turns off stuff like stack traces - the nimFrame/popFrame you see in your log) and use the new ORC GC with --gc:orc (it's generally more predictive), or even --gc:arc if your program doesn't form cycles.

@simonhf
Copy link
Author

simonhf commented Jul 23, 2022

Sweet! Thanks @Yardanico for all your tips which all worked out well, and I posted my experiences here [1] :-)

I noticed that --define:release invokes gcc with its -O3 option. And --define:release --opt:size invokes gcc with its -Os option. How to get Nim to invoke gcc with e.g. -O2 instead of -O3? In Nim forums then I see Nim developers posting Nim benchmark results with -O2 but after a little Googling I can't figure out how to get Nim to invoke gcc with e.g. -O2 instead of -O3?

[1] corelight/cwrap#2 (comment)

@Yardanico
Copy link
Collaborator

@simonhf well, people rarely use -O2, but if you want to, you just do --passC:"-O2" since user flags are passed after Nim-specific ones

@simonhf
Copy link
Author

simonhf commented Jul 23, 2022

@Yardanico thanks for the further tip!

Actually yes, I did see that option and try it, but it didn't work for me :-( Why not? So e.g. if I give Nim --passC:"-Os" --define:release or --define:release --passC:"-Os" then the gcc line that gets invoked always contains -Os -O3 in that order, and so the -O3 continues to have precedence.

since user flags are passed after Nim-specific ones

Maybe this desired behavior is no longer working as expected?

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

No branches or pull requests

2 participants