Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 1 Oct 2018 15:52:51 +0000
From:      Brooks Davis <brooks@freebsd.org>
To:        Goran Meki?? <meka@tilda.center>
Cc:        freebsd-current@freebsd.org
Subject:   Re: Clang cross-compiling to Cortex-M4 (ARM)
Message-ID:  <20181001155251.GA87608@spindle.one-eyed-alien.net>
In-Reply-To: <20180930122026.em7hxzjvnwudaa2l@hal9000.home.meka.rs>
References:  <20180930122026.em7hxzjvnwudaa2l@hal9000.home.meka.rs>

next in thread | previous in thread | raw e-mail | index | archive | help

--ReaqsoxgOBHFXBhH
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Sun, Sep 30, 2018 at 02:20:26PM +0200, Goran Meki?? wrote:
> Hello,
>=20
> With Clang 4.0 cross-compiling works, but any later versions (I tried
> 5.0, 6.0 and 7.0 from packages) fails. This is the simple test program:
>=20
> #include <stdio.h>
>=20
> int main() {
>   return 0;
> }
>=20
>=20
> These are the results:
>=20
> clang -fno-builtin -nostdlib -ffreestanding -target arm-none-eabi -march=
=3Darmv7-m -mcpu=3Dcortex-m4 -o test test.c
> test.c:1:10: fatal error: 'stdio.h' file not found
> #include <stdio.h>
>          ^~~~~~~~~
> 1 error generated.
>=20
> clang40 -fno-builtin -nostdlib -ffreestanding -target arm-none-eabi -marc=
h=3Darmv7-m -mcpu=3Dcortex-m4 -o test test.c
> /usr/local/bin/arm-none-eabi-ld: warning: cannot find entry symbol _start=
; defaulting to 0000000000008000
>=20
>=20
> System clang is 6.0.1, but it's the same with the one from packages (to
> be precise, clang60 command). I suppose this is more suitable for LLVM
> mailing list, but I wanted to check if there's something specific on
> FreeBSD I should know about before I write there? Also, this does
> compile:
>=20
> clang -fno-builtin -nostdlib -ffreestanding -target arm-none-eabi -march=
=3Darmv7-m -mcpu=3Dcortex-m4 -isystem /usr/include -o test test.c
> /usr/bin/ld.lld: warning: cannot find entry symbol _start; defaulting to =
0x11000

It appears that post-4.0 clang dropped /usr/include from the include
path in this case.  You can see this with the --verbose flag:

$ clang40 -fno-builtin -nostdlib -ffreestanding -target arm-none-eabi
-march=3Darmv7-m -mcpu=3Dcortex-m4 -c -o test test.c --verbose    =20
clang version 4.0.1 (tags/RELEASE_401/final)
Target: arm-none--eabi
Thread model: posix
InstalledDir: /usr/local/llvm40/bin
 "/usr/local/llvm40/bin/clang-4.0" -cc1 -triple thumbv7em-none--eabi
-emit-obj -mrelax-all -disable-free -main-file-name test.c
-mrelocation-model static -mthread-model posix -mdisable-fp-elim
-fmath-errno -masm-verbose -mconstructor-aliases -target-cpu cortex-m4
-target-feature +soft-float-abi -target-feature +strict-align
-target-abi aapcs -mfloat-abi soft -v -dwarf-column-info
-debugger-tuning=3Dgdb -coverage-notes-file
/home/bed22/git/freebsd/test.gcno -resource-dir
/usr/local/llvm40/bin/../lib/clang/4.0.1 -fdebug-compilation-dir
/home/bed22/git/freebsd -ferror-limit 19 -fmessage-length 80
-ffreestanding -fallow-half-arguments-and-returns -fno-builtin
-fno-signed-char -fobjc-runtime=3Dgcc -fdiagnostics-show-option
-fcolor-diagnostics -o test -x c test.c
clang -cc1 version 4.0.1 based upon LLVM 4.0.1 default target
x86_64-portbld-freebsd11.1
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /usr/local/llvm40/bin/../lib/clang/4.0.1/include
 /usr/include
End of search list.


$ clang60 -fno-builtin -nostdlib -ffreestanding -target arm-none-eabi
-march=3Darmv7-m -mcpu=3Dcortex-m4 -c -o test test.c --verbose    =20
clang version 6.0.1 (tags/RELEASE_601/final)
Target: arm-none--eabi
Thread model: posix
InstalledDir: /usr/local/llvm60/bin
 "/usr/local/llvm60/bin/clang-6.0" -cc1 -triple thumbv7em-none--eabi -emit-=
obj -mrelax-all -disable-free -main-file-name test.c -mrelocation-model sta=
tic -mthread-model posix -mdisable-fp-elim -fmath-errno -no-integrated-as -=
mconstructor-aliases -ffreestanding -nostdsysteminc -target-cpu cortex-m4 -=
target-feature +soft-float-abi -target-feature -crc -target-feature +dsp -t=
arget-feature -ras -target-feature -dotprod -target-feature -hwdiv-arm -tar=
get-feature +hwdiv -target-feature +strict-align -target-abi aapcs -mfloat-=
abi soft -fallow-half-arguments-and-returns -dwarf-column-info -debugger-tu=
ning=3Dgdb -v -coverage-notes-file /home/bed22/git/freebsd/test.gcno -resou=
rce-dir /usr/local/llvm60/lib/clang/6.0.1 -internal-isystem /usr/local/llvm=
60/lib/clang/6.0.1/include -internal-isystem include -fdebug-compilation-di=
r /home/bed22/git/freebsd -ferror-limit 19 -fmessage-length 80 -fno-builtin=
 -fno-signed-char -fobjc-runtime=3Dgcc -fdiagnostics-show-option -fcolor-di=
agnostics -o test -x c test.c
clang -cc1 version 6.0.1 based upon LLVM 6.0.1 default target
x86_64-portbld-freebsd11.1
ignoring duplicate directory
"/usr/local/llvm60/lib/clang/6.0.1/include"
#include "..." search starts here:
#include <...> search starts here:
  /usr/local/llvm60/lib/clang/6.0.1/include
  include
End of search list.
In file included from test.c:1:
include/stdio.h:41:10: fatal error: 'sys/cdefs.h' file not found
#include <sys/cdefs.h>
          ^~~~~~~~~~~~~
1 error generated.


I think this change is correct (the system headers aren't generally the
headers you're looking for when targeting bare metal).  You can restore
the previous behavior (more or less) with "-isystem /usr/include".

-- Brooks

--ReaqsoxgOBHFXBhH
Content-Type: application/pgp-signature; name="signature.asc"

-----BEGIN PGP SIGNATURE-----

iQEcBAEBAgAGBQJbskLSAAoJEKzQXbSebgfAY4EH/0BR8f0FcTb0rhTkr91q+e5l
G2YUjujWR2uF6eFFKA7812xvRvFOgDFWFv8pKW+TZXF49fZTny5oXC7WdhVJBVj4
c3SUTdxbDj+TPXTlJOUsV3wTrNc4on8UJrZq/TKsCgAj8cUFyuDQl5W/NThD6yCd
M3mrKgnMQURUnId0shbyzfVYo1isKOCbck4m7EnU4X1IrVZAZrZqPvzOmYrpmZ9K
f9tNvKVSyahSDzB4qYqEl7x1nNcgs2BphQD8B5H0AjcxYVqg8Tz1xw6Jtap0NKPT
JPVsn0AO0uFi03ekS0B+K1UtLvkfeXdbTwodUO6LN94YDVdAVaB5SUMSTBJa3/Y=
=rQ7u
-----END PGP SIGNATURE-----

--ReaqsoxgOBHFXBhH--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20181001155251.GA87608>