- 
                Notifications
    
You must be signed in to change notification settings  - Fork 1.1k
 
Description
I've been experimenting with clang and thought it might be useful to open a discussion here before submitting pull requests. There might be some things I'm doing wrong, as I'm by no means an expert.
To get clang working, I use set(CMAKE_SYSROOT /usr/arm-none-eabi) in my CMakeLists, as well as:
-pico_find_compiler(PICO_COMPILER_CXX clang)
+pico_find_compiler(PICO_COMPILER_CXX clang++)
...
-set(CMAKE_CXX_FLAGS_INIT "${ARM_CLANG_COMMON_FLAGS}")
+set(CMAKE_CXX_FLAGS_INIT "${ARM_CLANG_COMMON_FLAGS} -isystem /usr/arm-none-eabi/include/c++/9.3.0/arm-none-eabi -isystem /usr/arm-none-eabi/include/c++/9.3.0/")
in the pico_arm_clang file.
Both -isystem flags seem necessary even after setting sysroot. Since one might choose to download newlib to any location, maybe the toolchain preloader should just check the CMAKE_SYSROOT flag first, then fall back to searching the usual locations (i.e. /usr/) automatically, and if nothing is found, have cmake raise an error?
From here I can get a blink project to compile and assemble to an elf with just a few modifications to the sdk source. The only things clang complains about are in the assembly files. The first two issues make no difference to the binaries with gcc (I've checked the disassembly) and should probably be changed anyway.
- use of the unsupported 
rsbswith 0 immediate which gcc assembles tonegsanyway, i.e. 
-    rsbs r0, #0
+    negs r0, r0
- extraneous 
#s in ldr commands, i.e. 
- ldr r7,=#SIO_BASE
+ ldr r7,=SIO_BASE
- use of unsigned suffix in defines... I don't like this fix because it's not in line with the coding style but I'm also not sure if any clang flags will help.
 
-#define PICO_STACK_SIZE 0x800u
+#define PICO_STACK_SIZE 0x800
- use of any arithmetic expressions in labels, the only examples I've encountered are in 
src/rp2_common/pico_double/double_v1_rom_shim.S: 
- adr r4,drsqrtapp-8            @ first eight table entries are never accessed because of the mantissa's leading 1
+ adr r4,drsqrtapp              @ first eight table entries are never accessed because of the mantissa's leading 1
+ subs r4,r4,#8
This seems a little stupid on Clang's part, but I can't find any other solutions.
With these changes, clang reaches the linking stage. Of course there's a whole bunch of issues with lld, but I haven't touched any of those yet.