├── .gitignore ├── README ├── go.sh └── test ├── build.sh └── main.c /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.so 3 | a.out 4 | .*.swp 5 | 6 | build*/ 7 | 8 | binutils 9 | llvm 10 | mclinker 11 | 12 | usr 13 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | An open source toolchain for the Hexagon DSP based off LLVM and MCLinker 2 | 3 | == Instructions == 4 | 5 | * ./go.sh 6 | * Copy the "Target files" from the SDK, see below 7 | ** TODO: Get a libc building for the DSP 8 | * Sadly, to build the demos "qaic" is still needed 9 | ** TODO: Replace qaic with something better that doesn't needlessly copy memory 10 | 11 | == freethedsp == 12 | 13 | DSP code you compile only works on Qualcomm Development boards by default. 14 | 15 | Check out freethedsp.com for a way to make it run on a phone with a Qualcomm processor. 16 | 17 | == Qualcomm SDK == 18 | 19 | Current tools version is 8.1.05. From the document "Tools release 7.x and 8.x are based wholly on the LLVM toolchain" 20 | If we want to support V60, we need at least version 7. 21 | 22 | == linker issue == 23 | 24 | clang doesn't currently work, because it needs to "hexagon-link" 25 | 26 | "hexagon-link" is hardcoded in line 289: 27 | https://clang.llvm.org/doxygen/Hexagon_8cpp_source.html 28 | 29 | Qualcomm has a closed source linker "ld.qcld": 30 | https://developer.qualcomm.com/forum/qdn-forums/software/snapdragon-llvm-compiler-android/32950 31 | 32 | lld doesn't seem to support hexagon? 33 | binutils bfd has no hexagon support? 34 | 35 | There's a complete open source toolchain: 36 | https://sourcery.mentor.com/GNUToolchain/release2800?@template=datasheet 37 | But it's only up to Hexagon v5 38 | 39 | CodeAurora has something: 40 | https://portland.source.codeaurora.org/patches/quic/hexagon/ 41 | https://portland.source.codeaurora.org/patches/quic/hexagon/4.0/ 42 | 43 | Most up to date linker I've found: 44 | https://portland.source.codeaurora.org/patches/quic/hexagon/V5/ 45 | 46 | This talks about the switch to "QCLinker" based off "MCLinker" which is open source 47 | https://www.linuxplumbersconf.org/2015/ocw//system/presentations/3243/original/LPC2015.pdf 48 | https://github.com/mclinker/mclinker 49 | 50 | ** FIXED! ** 51 | 52 | == Target files == 53 | 54 | Can't build them yet, they live in the SDK at: 55 | cp -Rv ~/Qualcomm/Hexagon_SDK/3.3.3/tools/HEXAGON_Tools/8.1.05/Tools/target usr/ 56 | 57 | Libraries @ usr/target/hexagon/lib/v60: 58 | 59 | Are these built with compiler-rt? 60 | $PREFIX/target/hexagon/lib/v60/G0/pic/initS.o 61 | $PREFIX/target/hexagon/lib/v60/G0/pic/libgcc.a 62 | $PREFIX/target/hexagon/lib/v60/G0/pic/finiS.o 63 | 64 | minimal for test to pass: 65 | mkdir -p usr/target/hexagon/lib/v60/G0/pic/ 66 | cp -Rv ~/Qualcomm/Hexagon_SDK/3.3.3/tools/HEXAGON_Tools/8.1.05/Tools/target/hexagon/lib/v60/G0/pic/{initS.o,libgcc.a,finiS.o} usr/target/hexagon/lib/v60/G0/pic/ 67 | 68 | == qaic == 69 | 70 | Think this is closed source Qualcomm. It's probably easy to build a better open source replacement, the stuff it generates seems to be needlessly slow. 71 | 72 | -------------------------------------------------------------------------------- /go.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # create output directory 4 | mkdir -p usr 5 | PREFIX=$PWD/usr 6 | 7 | download_to_directory() { 8 | mkdir -p $1 9 | curl $2 | tar xvfJ - -C $1 --strip-components=1 10 | } 11 | 12 | build_llvm() { 13 | pushd . 14 | # the basic three for llvm/clang 15 | # switch to 3.8.0 for MCLinker 16 | download_to_directory llvm http://releases.llvm.org/3.8.0/llvm-3.8.0.src.tar.xz 17 | download_to_directory llvm/tools/clang http://releases.llvm.org/3.8.0/cfe-3.8.0.src.tar.xz 18 | download_to_directory llvm/projects/compiler-rt http://releases.llvm.org/3.8.0/compiler-rt-3.8.0.src.tar.xz 19 | 20 | # llvm linker (doesn't support Hexagon?) 21 | #download_to_directory llvm/tools/lld http://releases.llvm.org/6.0.0/lld-6.0.0.src.tar.xz 22 | 23 | # no C++ support yet 24 | #download_to_directory llvm/projects/libcxx http://releases.llvm.org/6.0.0/libcxx-6.0.0.src.tar.xz 25 | #download_to_directory llvm/projects/libcxxabi http://releases.llvm.org/6.0.0/libcxxabi-6.0.0.src.tar.xz 26 | #download_to_directory llvm/projects/libunwind http://releases.llvm.org/6.0.0/libunwind-6.0.0.src.tar.xz 27 | 28 | # build directory 29 | mkdir -p build-llvm 30 | cd build-llvm 31 | 32 | # due to the hexagon-link issue, this doesn't work... 33 | #cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$PWD/../usr -DLLVM_DEFAULT_TARGET_TRIPLE=hexagon-unknown-linux-gnu -DLLVM_TARGET_ARCH=hexagon-unknown-linux-gnu -DLLVM_TARGETS_TO_BUILD=Hexagon -DLLVM_BUILD_EXTERNAL_COMPILER_RT=ON ../llvm 34 | 35 | cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$PREFIX -DLLVM_DEFAULT_TARGET_TRIPLE=hexagon-unknown--elf -DLLVM_TARGET_ARCH=hexagon-unknown--elf -DLLVM_TARGETS_TO_BUILD=Hexagon ../llvm 36 | 37 | make -j12 && make install 38 | popd 39 | } 40 | 41 | build_mclinker() { 42 | pushd . 43 | git clone git@github.com:geohot/mclinker.git --depth=1 44 | 45 | # autogen 46 | cd mclinker 47 | ./autogen.sh 48 | cd ../ 49 | 50 | mkdir -p build-mclinker 51 | cd build-mclinker 52 | ../mclinker/configure --enable-targets=hexagon --prefix=$PREFIX --with-llvm-config=$PREFIX/bin/llvm-config 53 | make -j12 && make install 54 | 55 | # link 56 | cd $PREFIX/bin 57 | ln -s ld.mcld hexagon-link 58 | popd 59 | } 60 | 61 | build_llvm 62 | build_mclinker 63 | 64 | -------------------------------------------------------------------------------- /test/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | export PATH=$PWD/../usr/bin/:$PATH 3 | clang -mv60 -mhvx-double -march=hexagon -mcpu=hexagonv60 -v -O2 -fpic -shared -o test.so main.c 4 | 5 | -------------------------------------------------------------------------------- /test/main.c: -------------------------------------------------------------------------------- 1 | int test() { 2 | return 1337; 3 | } 4 | 5 | --------------------------------------------------------------------------------