How do I pass -mfpmath=sse to LLVM using CLANG - macos

I am trying to compile a number of GNU tools on Mac OS X [10.8.5]. One of the optimization options I was able to use in the past is '-mfpmath=sse', but now I get the message:
clang: warning: argument unused during compilation: '-mfpmath=sse'
Now, llvm-gcc help says it supports '-mfpmath=sse', and clang has a method of passing things to llvm using '-mllvm ', but I cannot seem to make them work together.
Are these two options even meant to work together? If so, how?
What if I want to pass multiple LLVM arguments from CLANG using '-mllvm '? Is that possible, and if so, how?
Thanks,
Nick

You do not need this flag with clang. It defaults to "-mfpmath=sse" as soon as your processor does support it.
If you need to pass multiple options to LLVM directly (though, it seems to be pretty bad idea - you do not need to do so), you can just -mllvm multiple times, e.g. "-mllvm -foo -mllvm -bar".

Related

How to configure clang to use arm-none-eabi linker

I am trying to configure the last version of clang (6.0) to use the arm-none-eabi linker instead of the ld.lld but clang is always ignoring everything and keep asking for the ld.lld one. I am trying to build for cortex-m3 (lpx1769 board). How do I force clang to use the linker I want.
-fuse-ld=ld is also not working, so does clang no longer allow the use of any other linker?
So the answer was to use the flag:
-fuse-ld=path/to/linker-to-be-used
Remember that if you passing this flag to clang it will cause a warning that clang will not use this flag (only the linker stage will do). Thus if you compiling with -Werror, the warning will be turned into an error.
Moreover, because you are cross-compiling probably you will need to let the linker know where to find the target-specific libraries needed using the -L option. See this for more info:
https://clang.llvm.org/docs/CrossCompilation.html

What is clang's equivalent to --no-undefined gcc flag?

I am trying to build a project on Mac OS X using clang and it fails on linking step with ld: unknown option: --no-undefined, which is meant to built with gcc.
What's the clang equivalent for this option? (Please, don't advise to use gcc instead of clang.)
Also, a more generic question, is there any resource where one can find some kind of a "mapping" between gcc and clang (linker) options differences?
Thank you.
OS X uses a different linker. As #rubenvb points out, it's probably the one from Apple's binutils. If you run man ld, and search for "undefined", you will find this option:
-undefined treatment
Specifies how undefined symbols are to be treated. Options are: error, warning, suppress, or dynamic_lookup. The default is error.
So, replace -Wl,--no-undefined with -Wl,-undefined,error. Also, use the Force, Luke.

Is there something like -mcpu= but for OS selection in both gcc and clang? Or a "choose the nearest target that best matches"?

Simple question: I know -mcpu=xxx can be used to choose a target CPU on both gcc and clang. Is there an equivalent option but for target OS? Something like -mos=linux or -mos=freebsd?
Alternatively, is there a way I can specify an incomplete target triplet (say, x86_64-*-freebsd* or i686*linux*) and gcc/clang will autocomplete?
I ask this because FreeBSD and OpenBSD seem to use version-specific and package manager-specific (!) target triplets.
Thanks.
EDIT/UPDATE I've figured most of what I need out, the only thing I'm missing is: is there a way to specify the target to use on the gcc command line, like the -target switch to clang? for example: gcc -someoptionhere i686-linux? Or a way to know if I should be using the multilib target instead of a target triplet? :S Thanks...
All right, figured this out on my own (references at bottom).
-m is actually for specifying a target for multilib compilers.
For clang, a target triplet can be specified with the -target option. Any part of the triplet can be omitted; appropriate defaults will be chosen instead. So all I really need to say is [arch]-[OS] or [arch]-[OS]-[ABI]. Version numbers aren't important, see include/llvm/ADT/Triple.h in the LLVM source.
Unfortunately, contrary to what I originally believed, gcc does not work like this: each individual build of gcc is tied to a given target triple, and the unqualified gcc is usually hardlinked to a given target triple. That means I can't use any shortcuts like I can with clang; specifying the target triple is required.
So now I'm going to need to figure out what to do about supporting cross-compilation using gcc and clang with the same tool/build script (not configure, cmake, or scons). Thanks!
References:
https://gcc.gnu.org/install/specific.html
https://gcc.gnu.org/onlinedocs/gcc-4.9.0/gcc/Target-Options.html
https://gcc.gnu.org/onlinedocs/gcc-4.5.0/gcc/Target-Options.html
https://stackoverflow.com/a/4455746/3408572
http://clang.llvm.org/docs/CrossCompilation.html
http://wiki.osdev.org/Target_Triplet
redi in irc.freenode.net/#gcc
jroelofs in irc.oftc.net/#llvm

What to replace -static-libgcc with when using clang?

I'm trying to port to Macintosh OSX where clang is provided instead of gcc. When building on Linux with gcc, I pass -static-libgcc to gcc.
What is the nearest equivalent I might replace this option when using clang?
Probably this has already been sorted out, but for the sake of completeness,
-- you cannot not link with system libraries statically on mac, till you do some extra work of compiling crt0.o.
So, simply remove this flag.
Please see
stackoverflow.com/questions/5259249/creating-static-mac-os-x-c-build
https://developer.apple.com/library/mac/qa/qa1118/_index.html

Get list of default GCC warnings

I'd like to know if it's possible to get a list of warnings that are enabled in GCC when no -Wx or -W-no-x flags are specified? I need this because I've got 2 different GCC versions (namely 3.3 and 4.3) which react differently on the same code with the same compilation flags.
For example, 4.3 with no additional warning options throws a warning when signed-to-unsigned comparison occurs while 3.3 does only if -Wsign-compare flag. So, I'd like to figure out, which flags should I add to gcc-3.3 to force it to detect the same warnings 4.3 does by default.
For 4.3 I'd managed to get such list of warnings using gcc -Q --help=warnings | grep enabled, but 3.3 doesn't seems to provide such function. Does anybody know, how it can be done in any other way? Maybe the source file that defines warning states?
Regards,
Marvin
GCC command line options are usually defined in gcc/common.opt file.
Try searching for `Warning' keyword in this file.

Resources