Rev 7 | Rev 9 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 7 | Rev 8 | ||
|---|---|---|---|
| Line 123... | Line 123... | ||
| 123 | echo "QNX_HOST=${QNX_HOST}" |
123 | echo "QNX_HOST=${QNX_HOST}" |
| 124 | echo "QNX_TARGET=${QNX_TARGET}" |
124 | echo "QNX_TARGET=${QNX_TARGET}" |
| 125 | echo "MAKEFLAGS=${MAKEFLAGS}" |
125 | echo "MAKEFLAGS=${MAKEFLAGS}" |
| 126 | 126 | ||
| 127 | # create the QNX CMake toolchain file |
127 | # create the QNX CMake toolchain file |
| 128 | echo '# '${TARGET_TRIPLE}' CMake toolchain file by Pierre-Marie Baty <pm@pmbaty.com> |
128 | test -e "${TARGET_TRIPLE}.cmake" || echo '# '${TARGET_TRIPLE}' CMake toolchain file by Pierre-Marie Baty <pm@pmbaty.com> |
| 129 | 129 | ||
| 130 | SET(CMAKE_SYSTEM_NAME "QNX") |
130 | SET(CMAKE_SYSTEM_NAME "QNX") |
| 131 | SET(CMAKE_SYSTEM_VERSION "'${QNXSDK_VERSION}'") |
131 | SET(CMAKE_SYSTEM_VERSION "'${QNXSDK_VERSION}'") |
| 132 | 132 | ||
| 133 | SET(QNX "1") |
133 | SET(QNX "1") |
| Line 178... | Line 178... | ||
| 178 | # test if already patched |
178 | # test if already patched |
| 179 | grep -q "${2}" "../${LLVM_SOURCES_DIR}/${1}" && return |
179 | grep -q "${2}" "../${LLVM_SOURCES_DIR}/${1}" && return |
| 180 | # tell what we're about to do |
180 | # tell what we're about to do |
| 181 | echo "Patching ${1}..." |
181 | echo "Patching ${1}..." |
| 182 | # have a backup first |
182 | # have a backup first |
| 183 | test -f "${CURRENT_DIR}/$(echo "${1}"|tr '/' '.') [ |
183 | test -f "${CURRENT_DIR}/$(echo "${1}"|tr '/' '.') [ORIGINAL]" || cp "../${LLVM_SOURCES_DIR}/${1}" "${CURRENT_DIR}/$(echo "${1}"|tr '/' '.') [ORIGINAL]" |
| 184 | # perform the patch |
184 | # perform the patch |
| 185 | sed -E "${3}" "${CURRENT_DIR}/$(echo "${1}"|tr '/' '.') [ |
185 | sed -E "${3}" "${CURRENT_DIR}/$(echo "${1}"|tr '/' '.') [ORIGINAL]" > "${CURRENT_DIR}/$(echo "${1}"|tr '/' '.') [PATCHED]" |
| 186 | # verify that we did it successfully |
186 | # verify that we did it successfully |
| 187 | if ! grep -q "${2}" "${CURRENT_DIR}/$(echo "${1}"|tr '/' '.') [ |
187 | if ! grep -q "${2}" "${CURRENT_DIR}/$(echo "${1}"|tr '/' '.') [PATCHED]"; then |
| 188 | echo "Error: the file ${1} could not be patched. Please investigate and fix manually." | fold -s -w 79; exit 1 |
188 | echo "Error: the file ${1} could not be patched. Please investigate and fix manually." | fold -s -w 79; exit 1 |
| 189 | fi |
189 | fi |
| 190 | # and put the patched file in place |
190 | # and put the patched file in place |
| 191 | cp -f "${CURRENT_DIR}/$(echo "${1}"|tr '/' '.') [ |
191 | cp -f "${CURRENT_DIR}/$(echo "${1}"|tr '/' '.') [PATCHED]" "../${LLVM_SOURCES_DIR}/${1}" || exit 1 |
| 192 | } |
192 | } |
| 193 | - | ||
| 194 | 193 | ||
| 195 | # patch llvm/Support/Unix/Path.inc if not done yet |
194 | # patch llvm/Support/Unix/Path.inc if not done yet |
| 196 | # replace |
195 | # replace [defined(__FreeBSD_kernel__)] with [(defined(__FreeBSD_kernel__) || defined(__QNXNTO__))] |
| 197 | # RATIONALE: the concerned parts of the QNX platform SDK (/usr/include/devs/*) are actually largely based on FreeBSD code, to conveniently use the FreeBSD network stack. |
196 | # RATIONALE: the concerned parts of the QNX platform SDK (/usr/include/devs/*) are actually largely based on FreeBSD code, to conveniently use the FreeBSD network stack. |
| 198 | # NONETHELESS, QNX *IS NOT* FreeBSD and "__FreeBSD_kernel__" *SHOULD NOT* be defined, else userland code may falsely assume a genuine FreeBSD include tree to be available, |
197 | # NONETHELESS, QNX *IS NOT* FreeBSD and "__FreeBSD_kernel__" *SHOULD NOT* be defined, else userland code may falsely assume a genuine FreeBSD include tree to be available, |
| 199 | # which leads to compilation errors caused by include files assumed to be there whereas they are in fact nowhere to be found (ex: /usr/include/sys/user.h, among others). |
198 | # which leads to compilation errors caused by include files assumed to be there whereas they are in fact nowhere to be found (ex: /usr/include/sys/user.h, among others). |
| 200 | # The QNX8 platform SDK has thus been patched to NOT define __FreeBSD_kernel__ when the -DDONT_DEFINE___FreeBSD_kernel__ flag is passed, and the feature tests in Path.inc |
199 | # The QNX8 platform SDK has thus been patched to NOT define __FreeBSD_kernel__ when the -DDONT_DEFINE___FreeBSD_kernel__ flag is passed, and the feature tests in Path.inc |
| 201 | # that branch into FreeBSD APIs (which ones *are* exposed in the QNX libc since QNX largely shares FreeBSD code) are about to be patched right now to accept __QNXNTO__ too. |
200 | # that branch into FreeBSD APIs (which ones *are* exposed in the QNX libc since QNX largely shares FreeBSD code) are about to be patched right now to accept __QNXNTO__ too. |
| 202 | # Additionally, support for statfs()/fstatfs() has been restored in the QNX8 platform SDK in /usr/include/devs/sys/mount.h where it was claimed but absent from the QNX8 libc. |
201 | # Additionally, support for statfs()/fstatfs() has been restored in the QNX8 platform SDK in /usr/include/devs/sys/mount.h where it was claimed but absent from the QNX8 libc. |
| 203 | # FIXME: these hacks should be moved elsewhere not to pollute the QNX8 platform SDK -- it *SHOULD* be possible to build without devs |
202 | # FIXME: these hacks should be moved elsewhere not to pollute the QNX8 platform SDK -- it *SHOULD* be possible to build without devs |
| 204 | backup_and_patch_if_necessary "llvm/lib/Support/Unix/Path.inc" __QNXNTO__ 's/defined\(__FreeBSD_kernel__\)/\(defined\(__FreeBSD_kernel__\) \|\| \defined\(__QNXNTO__\)\)/g' |
203 | backup_and_patch_if_necessary "llvm/lib/Support/Unix/Path.inc" __QNXNTO__ 's/defined\(__FreeBSD_kernel__\)/\(defined\(__FreeBSD_kernel__\) \|\| \defined\(__QNXNTO__\)\)/g' |
| 205 | 204 | ||
| 206 | # patch lldb/Source/Host/common/Host.cpp if not done yet |
205 | # patch lldb/Source/Host/common/Host.cpp if not done yet |
| 207 | # replace |
206 | # replace [defined(SIGINFO)] with [(defined(SIGINFO) && !defined(__QNXNTO__))] |
| 208 | # RATIONALE: the QNX people defined SIGINFO to the value of SIGUSR1 for a mysterious reason, defeating the purpose of SIGUSR1 |
207 | # RATIONALE: the QNX people defined SIGINFO to the value of SIGUSR1 for a mysterious reason, defeating the purpose of SIGUSR1 |
| 209 | # which should be a User-Definable signal as mandated by POSIX. Consequently, userland code that enumerates POSIX signals |
208 | # which should be a User-Definable signal as mandated by POSIX. Consequently, userland code that enumerates POSIX signals |
| 210 | # hits twice the same value and all is left to solve this problem is to filter either one out. Since SIGINFO, contrarily to SIGUSR1, |
209 | # hits twice the same value and all is left to solve this problem is to filter either one out. Since SIGINFO, contrarily to SIGUSR1, |
| 211 | # is an optional signal, this is the value that will be left out - even if on QNX nobody can actually use SIGUSR1's value. |
210 | # is an optional signal, this is the value that will be left out - even if on QNX nobody can actually use SIGUSR1's value. |
| 212 | backup_and_patch_if_necessary "lldb/source/Host/common/Host.cpp" __QNXNTO__ 's/defined\(SIGINFO\)/\(defined\(SIGINFO\) \&\& \!defined\(__QNXNTO__\)\)/g' |
211 | backup_and_patch_if_necessary "lldb/source/Host/common/Host.cpp" __QNXNTO__ 's/defined\(SIGINFO\)/\(defined\(SIGINFO\) \&\& \!defined\(__QNXNTO__\)\)/g' |
| Line 217... | Line 216... | ||
| 217 | # if (ptrace(PT_TRACE_ME, 0, nullptr, 0) == -1) // <--- undefined: ptrace, PT_TRACE_ME |
216 | # if (ptrace(PT_TRACE_ME, 0, nullptr, 0) == -1) // <--- undefined: ptrace, PT_TRACE_ME |
| 218 | 217 | ||
| 219 | # -D LLVM_ENABLE_PROJECTS="clang;lld;lldb" \ |
218 | # -D LLVM_ENABLE_PROJECTS="clang;lld;lldb" \ |
| 220 | 219 | ||
| 221 | # patch compiler-rt/lib/builtins/enable_execute_stack.c if not done yet |
220 | # patch compiler-rt/lib/builtins/enable_execute_stack.c if not done yet |
| 222 | # replace |
221 | # replace [#include "int_lib.h"] with [#ifdef __QNXNTO__\n#define _QNX_SOURCE 1\n#endif\n#include "int_lib.h"] |
| 223 | # RATIONALE: the QNX people decided to hide most of the UNIX APIs of their libc behind a mandatory _QNX_SOURCE definition to separate the Neutrino primitives from the rest maybe. |
222 | # RATIONALE: the QNX people decided to hide most of the UNIX APIs of their libc behind a mandatory _QNX_SOURCE definition to separate the Neutrino primitives from the rest maybe. |
| 224 | # This name does not "enforce" any standard at all (like _POSIX_SOURCE and similar names), it's just a convenient hack for the QNX people to hide stuff. |
223 | # This name does not "enforce" any standard at all (like _POSIX_SOURCE and similar names), it's just a convenient hack for the QNX people to hide stuff. |
| 225 | # To put things back on track and expose the POSIX interfaces of their libc to the world, _QNX_SOURCE has been added to the toolchain CMake file, but it happens that |
224 | # To put things back on track and expose the POSIX interfaces of their libc to the world, _QNX_SOURCE has been added to the toolchain CMake file, but it happens that |
| 226 | # when building compiler-rt specifically, the CMAKE_C_FLAGS directive is ignored. Patching the source file seems like the best option to fix that. |
225 | # when building compiler-rt specifically, the CMAKE_C_FLAGS directive is ignored. Patching the source file seems like the best option to fix that. |
| 227 | backup_and_patch_if_necessary "compiler-rt/lib/builtins/enable_execute_stack.c" __QNXNTO__ 's/#include "int_lib.h"/#ifdef __QNXNTO__\n#define _QNX_SOURCE 1\n#endif\n#include "int_lib.h"/g' |
226 | backup_and_patch_if_necessary "compiler-rt/lib/builtins/enable_execute_stack.c" __QNXNTO__ 's/#include "int_lib.h"/#ifdef __QNXNTO__\n#define _QNX_SOURCE 1\n#endif\n#include "int_lib.h"/g' |
| - | 227 | ||
| - | 228 | # patch libunwind/src/RWMutex.hpp |
|
| - | 229 | # replace [#include <pthread.h>] with [#ifdef __QNXNTO__\n#define __EXT_QNX\n#define __EXT_POSIX1_200112\n#endif\n#include <pthread.h>] |
|
| - | 230 | # RATIONALE: the pthreads implementation in QNX 'steals' things from the POSIX.1 standard and hides them behind the __EXT_QNX macro, |
|
| - | 231 | # which is defined when either _QNX_SOURCE or __EXT without anything else is defined. This is not correct and low-level libraries |
|
| - | 232 | # such as libunwind that do not define either of those fail to build. Also note that a FreeBSD-compatible header was added to the QNX8 |
|
| - | 233 | # platform SDK: /usr/include/link.h, which defines Elf types as Elf64/Elf32 types depending on the architecture and adds some glue. |
|
| - | 234 | backup_and_patch_if_necessary "libunwind/src/RWMutex.hpp" __QNXNTO__ 's/#include <pthread.h>/#ifdef __QNXNTO__\n#define __EXT_QNX\n#define __EXT_POSIX1_200112\n#endif\n#include <pthread.h>/g' |
|
| 228 | 235 | ||
| 229 | # now configure LLVM |
236 | # now configure LLVM |
| 230 | echo "Configuring LLVM build..." |
237 | echo "Configuring LLVM build..." |
| 231 | cmake \ |
238 | cmake \ |
| 232 | -D CMAKE_TOOLCHAIN_FILE="${TARGET_TRIPLE}.cmake" \ |
239 | -D CMAKE_TOOLCHAIN_FILE="${TARGET_TRIPLE}.cmake" \ |
| Line 235... | Line 242... | ||
| 235 | -D CMAKE_STAGING_PREFIX="/usr/bin" \ |
242 | -D CMAKE_STAGING_PREFIX="/usr/bin" \ |
| 236 | -D LLVM_HOST_TRIPLE="${TARGET_TRIPLE}" \ |
243 | -D LLVM_HOST_TRIPLE="${TARGET_TRIPLE}" \ |
| 237 | -D LLVM_ENABLE_PROJECTS="clang;lld" \ |
244 | -D LLVM_ENABLE_PROJECTS="clang;lld" \ |
| 238 | -D LLVM_ENABLE_RUNTIMES="compiler-rt;libcxx;libcxxabi;libunwind" \ |
245 | -D LLVM_ENABLE_RUNTIMES="compiler-rt;libcxx;libcxxabi;libunwind" \ |
| 239 | -D LLVM_TARGETS_TO_BUILD="AArch64;X86" \ |
246 | -D LLVM_TARGETS_TO_BUILD="AArch64;X86" \ |
| - | 247 | -D COMPILER_RT_BUILD_SANITIZERS="OFF" \ |
|
| 240 | -G Ninja \ |
248 | -G Ninja \ |
| 241 | "../${LLVM_SOURCES_DIR}/llvm" || exit 1 |
249 | "../${LLVM_SOURCES_DIR}/llvm" || exit 1 |
| 242 | 250 | ||
| 243 | # hijack the "bin" and "lib/clang" output directories and redirect them to the hypervisor's filesystem |
251 | # hijack the "bin" and "lib/clang" output directories and redirect them to the hypervisor's filesystem |
| 244 | test -e "${CURRENT_DIR}/llvm-build" && rm -rf "${CURRENT_DIR}/llvm-build" |
252 | test -e "${CURRENT_DIR}/llvm-build" && rm -rf "${CURRENT_DIR}/llvm-build" |