I want to run clang static analyzer on different target. Here is the makefile snip:
CC = <path to clang folder>/build/bin/clang
.
.
.
src/%.o: ../src/%.c
${CC} --target=powerpc -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(#:%.o=%.d)" -MT"$(#)" -o "$#" "$<"
I am trying to compile to powerpc. This is the command line and the output:
>> <path_to_llvm_folder>/llvm/tools/clang/tools/scan-build/scan-build --use-analyzer=<path_to_llvm_folder>/build/bin/clang make
scan-build: Using '<path_to_llvm_folder>/build/bin/clang' for static analysis
Building file: ../src/testing.c
Invoking: GCC C Compiler
<path to clang folder>/llvm/tools/clang/tools/scan-build/ccc-analyzer --target=powerpc -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/testing.d" -MT"src/testing.o" -o "src/testing.o" "../src/testing.c"
cc1: warning: command line option "-ftarget=powerpc" is valid for Java but not for C
Notice that although the makefile is calling clang - I am getting gcc warning...So how do I use clang to compile the code AND for static analysis for different target ?
found the solution. I think there is a bug in the ccc-analyzer script in the next param:
my %CompilerLinkerOptionMap = (
'-Wwrite-strings' => 0,
'-ftrapv-handler' => 1, # specifically call out separated -f flag
'-mios-simulator-version-min' => 0, # This really has 1 argument, but always has '='
'-isysroot' => 1,
'-arch' => 1,
'-m32' => 0,
'-m64' => 0,
'-stdlib' => 0, # This is really a 1 argument, but always has '='
'--sysroot' => 1,
'-target' => 1,
'-v' => 0,
'-mmacosx-version-min' => 0, # This is really a 1 argument, but always has '='
'-miphoneos-version-min' => 0 # This is really a 1 argument, but always has '='
);
the
'-target' => 1,
needs to be
'--target' => 1,
(with double '-')...
Related
I'm have a C Wasm module with the following import:
__attribute__((import_module("env"), import_name("runtime_exit"))) void exit(int);
I'm compiling with Clang 12.0.0 on Linux:
clang --target=wasm32 --no-standard-libraries \
-c -Ofast -o out.o in.c
With the package from my package manager (xbps), this works fine. In Nix (see below for the derivation), however (Clang 12.0.1), I get the following warning on nix-build:
tests/test.h:1:16: warning: unknown attribute 'import_module' ignored [-Wunknown-attributes]
__attribute__((import_module("env"), import_name("runtime_exit"))) void exit(int);
^~~~~~~~~~~~~~~~~~~~
tests/test.h:1:38: warning: unknown attribute 'import_name' ignored [-Wunknown-attributes]
__attribute__((import_module("env"), import_name("runtime_exit"))) void exit(int);
This is just a warning, but linking later fails: in fact, clang is attempting to link with ld, not wasm-ld or even lld.
My default.nix specifies:
{ pkgs ? import <nixpkgs> {} }:
let
stdenv = pkgs.llvmPackages_12.stdenv;
src = ./.; # etc, etc
in
stdenv.mkDerivation {
# --- snip ---
buildPhase = ''
clang --target=wasm32 --no-standard-libraries \
-c -Ofast -o $out/out.o in.c
'';
# --- snip ---
buildInputs = [ pkgs.clang_12 pkgs.lld_12 ];
}
I don't see why this shouldn't work, but all the different variations of packages I've tried using seem to suggest that I'm getting at the LLVM toolchain incorrectly.
If this isn't enough information, please let me know. Thanks!
Edit
It looks like Nix isn't respecting the --target argument:
$ nix-shell
[nix-shell:~/...]$ clang -target wasm32 --print-target-triple
x86_64-unknown-linux-gnu
[nix-shell:~/...]$ exit
$ clang --target=wasm32 --print-target-triple
wasm32
Despite the above, clang wasm32 as an available target.
The clang wrapper script given by Nix seems to do something. The compiler should be called with clang-[VERSION] instead of clang, for example as:
clang-12 --target=wasm32 --no-standard-libraries \
-c -std=c99 -Ofast -Wall -Werror -pedantic \
input.c -o output.o
I'm working on an LLVM backend for a new architecture and we need to have position independent executables. I can pass '-fPIE' on the clang command line, but I don't see any indication of this show up in the resulting LLVM IR. For example, if I run:
clang -v -emit-llvm -fPIC -O0 -S global_dat.c -o global_dat_x86_pic.ll
And then take a look at the resulting global_dat_x86_pic.ll file, I see the following near the bottom:
!0 = !{i32 1, !"PIC Level", i32 2}
Ok, makes sense.
However if I run:
clang -v -emit-llvm -fPIE -O0 -S global_dat.c -o global_dat_x86_pie.ll
I see that the two .ll files are identical. Near the bottom of global_cat_x86_pie.ll I see:
!0 = !{i32 1, !"PIC Level", i32 2}
Which is identical to the case where I ran with -fPIE. There's no indication of "PIE Level" in the .ll file. If this .ll file were passed on to llc how would llc know that -fPIE had been set on the clang command line?
I have run in gdb and see that in fact in the second case with -fPIE on the clang commandline there is an Opts.PIELevel (in $LLVM_HOME/tools/clang/lib/Frontend/CompilerInvocation.cpp) that gets set to 2 (in fact, both Opts.PIELevel and Opts.PICLevel are set to 2 in that case whereas in -fPIC is passed to clang only Opts.PICLevel is set to 2)
This depends on your default target triple, which I can't tell from your question. You can see what happens if you cut off the default architecture (or run a native clang on an arch that does support PIE)
For example, bare X86-64 shows this,
$ clang -c hello.c -target x86_64 -fPIE -emit-llvm -###
if you run that command, you'll find "-pie-level" "2" in the output, which is how llc (well, it's internal equivalent) knows about it.
The key here is that you'll have to arrange for your backend to do something with this flag. Certain platforms (like Darwin) just ignore it. If you happen to be experiment on an OSX host, you won't see -pie-level in the bogbrush output.
I am currently try to compile these files using HDF5
I have directly linked and included everything necessary ( I think) but still the compile unable to find the files that is needed
This is my Makefile:
CC = h5cc
FC = h5fc
LD = h5fc
FDEBUG = -std -g -traceback
CFLAGS = -g -O0 -Wall -pedantic
FFLAGS = -g -O0 -Wall -I$(H5DIR)/include -L$(H5DIR)/lib/libhdf5hl_fortran.a
LDFLAGS = -I$(H5DIR)/include -L$(H5DIR)/lib/libhdf5hl_fortran.a
#LDFLAGS = -I$(MKLROOT)/include -L$(MKLROOT) -mkl=sequential
# -opt-block-factor=16 -opt-prefetch=4 \
.SUFFIXES:
.SUFFIXES: .c .f .f90 .F90 .o
OBJS = timing.o \
kinds.o \
rw_matrix.o \
EXE = matmul_omp.exe
all: $(EXE)
$(EXE): $(OBJS) matmul_omp.o
$(LD) $(LDFLAGS) -o $# $^
.f90.o:
-$(RM) -f $*.o $*.mod
$(FC) $(FFLAGS) -c $<
.c.o:
$(CC) $(CFLAGS) -c $<
.PHONEY: clean
clean:
THis is the err:
h5fc -I/curc/tools/x_86_64/rh6/hdf5/1.8.13/szip/2.1/zlib/1.2.8/jpeglib/9a/openmpi/1.8.2/intel/13.0.0/include -L/curc/tools/x_86_64/rh6/hdf5/1.8.13/szip/2.1/zlib/1.2.8/jpeglib/9a/openmpi/1.8.2/intel/13.0.0/lib/libhdf5hl_fortran.a -o matmul_omp.exe timing.o matmul_omp.o
gfortran: /usr/lib64/libhdf5hl_fortran.a: No such file or directory
gfortran: /usr/lib64/libhdf5_hl.a: No such file or directory
gfortran: /usr/lib64/libhdf5_fortran.a: No such file or directory
gfortran: /usr/lib64/libhdf5.a: No such file or directory
As you can see that I directly link libhdf5hl_fortran.a. but i dont know why the error is giving a different directory /usr/lib64/
I think you have a couple of things wrong here.
If you are using h5fc then you shouldn't need to add all the include and lib paths. That is the whole point of the helper applications.
You are adding the paths that have Intel, yet your h5fc has a GNU (gfortran) error.
The gfortran build of HDF5 looks as if it does not have the fortran bindings built.
I would suggest trying the following. Using the full paths (as you have done) but call ifort instead of h5fc:
ifort -I/curc/tools/x_86_64/rh6/hdf5/1.8.13/szip/2.1/zlib/1.2.8/jpeglib/9a/openmpi/1.8.2/intel/13.0.0/include \
-L/curc/tools/x_86_64/rh6/hdf5/1.8.13/szip/2.1/zlib/1.2.8/jpeglib/9a/openmpi/1.8.2/intel/13.0.0/lib/libhdf5hl_fortran.a \
-o matmul_omp.exe timing.o matmul_omp.o
I try to build 2.5.0.3 driver from file 2011_0719_RT3070_RT3370_RT5370_RT5372_Linux_STA_V2.5.0.3_DPO.bz2 to RT5370 chipset.
Install STLinux 2.4 under Ubuntu 10.04.4 x32, make under kernel linux-sh4-2.5.32.59_stm24_0211. But I wrote /opt/STM/STLinux-2.2/devkit/sources/kernel/linux-sh4-2.5.32.59_stm24_0211 in path instead of STLinux-2.4, because Makefile have some defects:
install:
ifeq ($(TARGET), LINUX)
ifneq (,$(findstring 2.4,$(LINUX_SRC)))
$(MAKE) -C $(RT28xx_DIR)/os/linux -f Makefile.4 install
else
$(MAKE) -C $(RT28xx_DIR)/os/linux -f Makefile.6 install
endif
endif
The mention in a path 2.4 build a kernel as 2.4 that in my case a mistake.
Wrote in Makefile:
PLATFORM = ST
...
LINUX_SRC = /opt/STM/STLinux-2.2/devkit/sources/kernel/linux-sh4-2.5.32.59_stm24_0211
CROSS_COMPILE = /opt/STM/STLinux-2.2/devkit/sh4/bin/sh4-linux-
In ./os/linux/config.mk wrote:
HAS_WPA_SUPPLICANT=y
HAS_NATIVE_WPA_SUPPLICANT_SUPPORT=y
CC := sh4-linux-gcc
LD := sh4-linux-ld
Build at run make command. But have the error:
script/Makefile.build:49: *** CFLAGS was changed in "/home/vitaliy/drv_src/os/linux/Makefile". Fix it to use EXTRA_CFLAGS.
Founded strings at ./os/linux/config.mk:
ifeq ($(PLATFORM),ST)
CFLAGS := -D__KERNEL__ -I$(LINUX_SRC)/include -I$(RT28xx_DIR)/include -Wall -O2 -Wundef -Wstrict-prototypes -Wno-trigraphs -Wdeclaration-after-statement -Wno-pointer-sign -fno-strict-aliasing -fno-common -fomit-frame-pointer -ffreestanding -m4-nofpu -o $(WFLAGS)
export CFLAGS
endif
And change CFLAGS to EXTRA_CFLAGS in them.
Again error:
sh4-linux-gcc: error: -pg and -fomit-frame-pointer are incompatible.
Ok. Remove flag -fomit-frame-pointer.
Again error:
error: cpu/cache.h: No such file or directory.
In string:
WFLAGS := -DAGGREGATION_SUPPORT -DPIGGYBACK_SUPPORT -DWMM_SUPPORT -DLINUX -Wall -Wstrict-prototypes -Wno-trigraphs
Remove flag -DLINUX.
Again error with unknown types (for example: ./os/linux/../../common/crypt_md5.c:638:1: error: unknown type name 'VOID' and so on with types 'UCHAR', 'ULONG' etc).
Second way to build with help of
KBUILD_NOPEDANTIC=1 make without changes in sources files of drivers.
Error in this case too:
./os/linux/../../common/crypt_md5.c:28:23: fatal error: rt_config.h: No such file or directory.
What is wrong in my building? Or can I fix sources code and build driver for SH4-platform.
Thank you!
I recently got myself the same adapter, and I was trying to cross compile for ARM, and run into the same problem.
Basically, you just have to add the include folder from the root of the driver package.
I did these modifications to get it working:
in DRIVER_DIR/Makefile, added:
PLATFORM = MYPLATFORM
All other platforms are commented out.
Later in same file:
ifeq ($(PLATFORM),MYPLATFORM)
LINUX_SRC = /DIR_TO_MY_KERNEL_SRC/freescale_mainline/linux-mainline
CROSS_COMPILE = /DIR_TO_MY_CROSS_COMPILER/arm-unknown-linux-uclibcgnueabi-
CROSS_COMPILE_INCLUDE = /DRIVER_DIR/include /*Might not be necessary*/
endif
Then in DRIVER_DIR/os/linux/config.mk, added:
ifeq ($(PLATFORM),MYPLATFORM)
EXTRA_CFLAGS := $(WFLAGS) -I$(RT28xx_DIR)/include
endif
Also, please note that in your kernel configuration you need to have couple of flags enabled:
CONFIG_WEXT_CORE=y
CONFIG_WEXT_PROC=y
CONFIG_WEXT_SPY=y
CONFIG_WEXT_PRIV=y
You can find them under Device Drivers-->Network Device Support-->Wireless LAN-->IEEE 802.11 for Host AP
I compile it just like this now:
DRIVER_DIR$ ARCH=arm make
Hope it helps!
The excerpt form the configure scripts fails due to Killed: 9 error, which is that iOS 5 can only run signed apps. So I need to find a way to put ldid -s some where in these tests, only problem is where.
Anyone???
fails with
checking build system compiler gcc... no
checking build system compiler gcc -g -O2 ... no
checking build system compiler cc... no
checking build system compiler gcc... no
checking build system compiler c89... no
checking build system compiler c99... no
configure: error: Cannot find a build system compiler
and config.log
onfigure:15586: gcc -c -g -O2 conftest.c >&5
configure:15586: $? = 0
configure:15586: result: yes
configure:15586: checking sys/time.h presence
configure:15586: gcc -E conftest.c
configure:15586: $? = 0
configure:15586: result: yes
configure:15586: checking for sys/time.h
configure:15586: result: yes
configure:15677: checking build system compiler gcc
configure:15690: gcc conftest.c
conftest.c: In function 'main':
conftest.c:4: warning: incompatible implicit declaration of built-in function 'exit'
configure:15693: $? = 0
./configure: line 15675: 27218 Killed: 9 ./a.out
./configure: line 15695: ./b.out: No such file or directory
./configure: line 15695: ./a.exe: No such file or directory
./configure: line 15695: ./a_out.exe: No such file or directory
./configure: line 15695: ./conftest: No such file or directory
configure:15700: result: no
configure:15677: checking build system compiler gcc -g -O2
configure:15690: gcc -g -O2 conftest.c
conftest.c: In function 'main':
conftest.c:4: warning: incompatible implicit declaration of built-in function 'exit'
configure:15693: $? = 0
./configure: line 15675: 27234 Killed: 9 ./a.out
./configure: line 15695: ./b.out: No such file or directory
./configure: line 15695: ./a.exe: No such file or directory
./configure: line 15695: ./a_out.exe: No such file or directory
./configure: line 15695: ./conftest: No such file or directory
configure:15700: result: no
And finally the ./configure script..
if test -n "$CC_FOR_BUILD"; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking build system compiler $CC_FOR_BUILD" >&5
$as_echo_n "checking build system compiler $CC_FOR_BUILD... " >&6; }
# remove anything that might look like compiler output to our "||" expression
rm -f conftest* a.out b.out a.exe a_out.exe
cat >conftest.c <<EOF
int
main ()
{
exit(0);
}
EOF
gmp_compile="$CC_FOR_BUILD conftest.c"
cc_for_build_works=no
if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$gmp_compile\""; } >&5
(eval $gmp_compile) 2>&5
ac_status=$?
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }; then
if (./a.out || ./b.out || ./a.exe || ./a_out.exe || ./conftest) >&5 2>&1; then
cc_for_build_works=yes
fi
fi
rm -f conftest* a.out b.out a.exe a_out.exe
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $cc_for_build_works" >&5
$as_echo "$cc_for_build_works" >&6; }
if test "$cc_for_build_works" = yes; then
:
else
as_fn_error $? "Specified CC_FOR_BUILD doesn't seem to work" "$LINENO" 5
fi
elif test -n "$HOST_CC"; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking build system compiler $HOST_CC" >&5
$as_echo_n "checking build system compiler $HOST_CC... " >&6; }
# remove anything that might look like compiler output to our "||" expression
rm -f conftest* a.out b.out a.exe a_out.exe
cat >conftest.c <<EOF
int
main ()
{
exit(0);
}
I have to admit that my ability to read anything but the simplest shell scripts is pretty poor, but basically, you need to fake codesign the executable before you run it. It looks like the executable you want to run is called conftest, right? So, try signing it in this block:
if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$gmp_compile\""; } >&5
(eval $gmp_compile) 2>&5
ac_status=$?
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }; then
#begin added code
ldid -S ./conftest
#end added code
if (./a.out || ./b.out || ./a.exe || ./a_out.exe || ./conftest) >&5 2>&1; then
cc_for_build_works=yes
fi
fi
Obviously, you might need to supply the full path to ldid (e.g. /usr/bin/ldid) if it's not found in the existing PATH.
Update: per poster's comment below, a.out is actually the executable that needs to be signed, not conftest.