mirror of
https://github.com/apache/nuttx.git
synced 2026-08-01 20:28:58 +00:00
tools/rust: Fix aarch64 NuttX Rust target specs
Add a custom aarch64 Mach-O Rust target for macOS sim builds and use it instead of an Apple Darwin Rust target. This keeps Rust cfg values aligned with NuttX while producing Mach-O objects required by the simulator link. Also align sim host handling for aarch64 Linux by detecting `aarch64` as `HOST_ARM64` and avoiding x86-specific `-mcmodel` and `-no-pie` options on ARM64 hosts. Signed-off-by: Shoji Tokunaga <toku@mac.com>
This commit is contained in:
parent
efaebbba43
commit
7c38d58675
6 changed files with 79 additions and 18 deletions
|
|
@ -792,10 +792,9 @@ else()
|
|||
OUTPUT nuttx.rel
|
||||
COMMAND
|
||||
${CMAKE_C_COMPILER} ARGS -r $<$<BOOL:${CONFIG_SIM_M32}>:-m32>
|
||||
$<$<BOOL:${CONFIG_HOST_LINUX}>:-Wl,-z,noexecstack>
|
||||
$<TARGET_OBJECTS:sim_head> $<$<NOT:$<BOOL:${APPLE}>>:-Wl,--start-group>
|
||||
${nuttx_libs_paths} $<$<NOT:$<BOOL:${APPLE}>>:-Wl,--end-group> -o
|
||||
nuttx.rel
|
||||
$<$<BOOL:${LINUX}>:-Wl,-z,noexecstack> $<TARGET_OBJECTS:sim_head>
|
||||
$<$<NOT:$<BOOL:${APPLE}>>:-Wl,--start-group> ${nuttx_libs_paths}
|
||||
$<$<NOT:$<BOOL:${APPLE}>>:-Wl,--end-group> -o nuttx.rel
|
||||
COMMAND ${CMAKE_OBJCOPY} --redefine-syms=nuttx-names.dat nuttx.rel
|
||||
DEPENDS ${nuttx_libs} sim_head sim_redefine_symbols
|
||||
COMMAND_EXPAND_LISTS)
|
||||
|
|
|
|||
|
|
@ -20,8 +20,24 @@
|
|||
#
|
||||
# ##############################################################################
|
||||
|
||||
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux")
|
||||
set(SIM_HOST_LINUX true)
|
||||
elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
|
||||
set(SIM_HOST_MACOS true)
|
||||
endif()
|
||||
|
||||
if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "^(x86_64|amd64|AMD64)$")
|
||||
set(SIM_HOST_X86_64 true)
|
||||
elseif(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "^(i[3-6]86|x86)$")
|
||||
set(SIM_HOST_X86_32 true)
|
||||
elseif(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "^(aarch64|arm64)$")
|
||||
set(SIM_HOST_ARM64 true)
|
||||
elseif(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "^(arm|armv[0-9].*)$")
|
||||
set(SIM_HOST_ARM true)
|
||||
endif()
|
||||
|
||||
if(APPLE AND CONFIG_SIM_TOOLCHAIN_GCC)
|
||||
if(CONFIG_HOST_ARM64)
|
||||
if(SIM_HOST_ARM64)
|
||||
find_program(CMAKE_C_ELF_COMPILER aarch64-elf-gcc)
|
||||
find_program(CMAKE_CXX_ELF_COMPILER aarch64-elf-g++)
|
||||
else()
|
||||
|
|
@ -41,14 +57,14 @@ if(WIN32)
|
|||
return()
|
||||
endif()
|
||||
|
||||
if(CONFIG_HOST_LINUX)
|
||||
if(SIM_HOST_LINUX)
|
||||
set(CMAKE_LD ld)
|
||||
set(CMAKE_PREPROCESSOR cc -E -P -x c)
|
||||
set(CMAKE_STRIP strip --strip-unneeded)
|
||||
endif()
|
||||
|
||||
# LLVM style architecture flags
|
||||
if(CONFIG_HOST_X86_64)
|
||||
if(SIM_HOST_X86_64)
|
||||
if(CONFIG_SIM_M32)
|
||||
set(LLVM_ARCHTYPE "x86")
|
||||
set(LLVM_CPUTYPE "i686")
|
||||
|
|
@ -56,18 +72,18 @@ if(CONFIG_HOST_X86_64)
|
|||
set(LLVM_ARCHTYPE "x86_64")
|
||||
set(LLVM_CPUTYPE "skylake")
|
||||
endif()
|
||||
elseif(CONFIG_HOST_X86_32)
|
||||
elseif(SIM_HOST_X86_32)
|
||||
set(LLVM_ARCHTYPE "x86")
|
||||
set(LLVM_CPUTYPE "i686")
|
||||
elseif(CONFIG_HOST_ARM64)
|
||||
elseif(SIM_HOST_ARM64)
|
||||
set(LLVM_ARCHTYPE "aarch64")
|
||||
set(LLVM_CPUTYPE "cortex-a53")
|
||||
elseif(CONFIG_HOST_ARM)
|
||||
elseif(SIM_HOST_ARM)
|
||||
set(LLVM_ARCHTYPE "arm")
|
||||
set(LLVM_CPUTYPE "cortex-a9")
|
||||
endif()
|
||||
|
||||
if(CONFIG_HOST_LINUX OR CONFIG_HOST_MACOS)
|
||||
if(SIM_HOST_LINUX OR SIM_HOST_MACOS)
|
||||
set(LLVM_ABITYPE "sysv")
|
||||
elseif(WIN32)
|
||||
set(LLVM_ABITYPE "msvc")
|
||||
|
|
@ -230,7 +246,14 @@ endif()
|
|||
if(CONFIG_SIM_M32)
|
||||
add_compile_options(-m32)
|
||||
add_link_options(-m32)
|
||||
elseif(NOT APPLE)
|
||||
elseif(NOT APPLE AND NOT SIM_HOST_ARM64)
|
||||
# To compile 64-bit Sim, adding no-pie is necessary to prevent linking errors
|
||||
# but this may cause other issues on Ubuntu 20.
|
||||
#
|
||||
# NOTE: HOST_ARM64 is also excluded -- Ubuntu/Debian arm64 toolchains ship
|
||||
# only libgcc_s.so.1 (no libgcc_s.a), and -no-pie forces gcc to look for the
|
||||
# static archive; skipping it lets gcc use the default PIE link path which
|
||||
# works correctly on aarch64 hosts.
|
||||
add_compile_options(-no-pie)
|
||||
add_link_options(-Wl,-no-pie)
|
||||
endif()
|
||||
|
|
@ -254,6 +277,6 @@ else()
|
|||
add_link_options(-Wl,-Ttext-segment=0x40000000)
|
||||
endif()
|
||||
|
||||
if(CONFIG_HOST_LINUX)
|
||||
if(SIM_HOST_LINUX)
|
||||
add_link_options(-Wl,-z,noexecstack)
|
||||
endif()
|
||||
|
|
|
|||
|
|
@ -151,7 +151,7 @@ ifeq ($(CONFIG_SIM_M32),y)
|
|||
else
|
||||
ARCHCFLAGS += -fno-pic
|
||||
ARCHCXXFLAGS += -fno-pic
|
||||
ifneq ($(CONFIG_HOST_MACOS),y)
|
||||
ifeq ($(CONFIG_HOST_X86_64),y)
|
||||
ARCHCFLAGS += -mcmodel=medium
|
||||
ARCHCXXFLAGS += -mcmodel=medium
|
||||
endif
|
||||
|
|
@ -167,7 +167,7 @@ ifeq ($(CONFIG_HOST_X86_64),y)
|
|||
LLVM_ARCHTYPE := x86_64
|
||||
LLVM_CPUTYPE := skylake
|
||||
endif
|
||||
else ifeq ($(CONFIG_HOST_X86_32),y)
|
||||
else ifeq ($(CONFIG_HOST_X86),y)
|
||||
LLVM_ARCHTYPE := x86
|
||||
LLVM_CPUTYPE := i686
|
||||
else ifeq ($(CONFIG_HOST_ARM64),y)
|
||||
|
|
|
|||
|
|
@ -110,7 +110,7 @@ function(nuttx_sethost)
|
|||
elseif(ARCHITECTURE STREQUAL "arm")
|
||||
message(" Select HOST_ARM=y")
|
||||
list(APPEND NUTTX_SYSTEM_SETHOST "HOST_ARM=y")
|
||||
elseif(ARCHITECTURE STREQUAL "arm64")
|
||||
elseif(ARCHITECTURE MATCHES "^(arm64|aarch64)$")
|
||||
message(" Select HOST_ARM64=y")
|
||||
list(APPEND NUTTX_SYSTEM_SETHOST "HOST_ARM64=y")
|
||||
endif()
|
||||
|
|
|
|||
|
|
@ -41,10 +41,14 @@ ifeq ($(CONFIG_ARCH_SIM),y)
|
|||
RUSTFLAGS += --target i686-unknown-linux-gnu
|
||||
else
|
||||
# For other archs, such as aarch64, arm etc
|
||||
RUSTFLAGS += --target $(LLVM_ARCHTYPE)-unknown-linux-gnu
|
||||
RUSTFLAGS += --target $(LLVM_ARCHTYPE)-unknown-linux-gnu
|
||||
endif
|
||||
else ifeq ($(CONFIG_HOST_MACOS),y)
|
||||
RUSTFLAGS += --target $(LLVM_ARCHTYPE)-apple-darwin
|
||||
ifeq ($(LLVM_ARCHTYPE),aarch64)
|
||||
RUSTFLAGS += --target $(TOPDIR)/tools/aarch64-unknown-nuttx-macho.json
|
||||
else
|
||||
$(error Unsupported Rust SIM target on macOS: LLVM_ARCHTYPE=$(LLVM_ARCHTYPE))
|
||||
endif
|
||||
endif
|
||||
else ifeq ($(CONFIG_ARCH_RISCV),y)
|
||||
# Target triple is riscv[32|64][isa]-unknown-none-elf
|
||||
|
|
|
|||
35
tools/aarch64-unknown-nuttx-macho.json
Normal file
35
tools/aarch64-unknown-nuttx-macho.json
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
{
|
||||
"arch": "aarch64",
|
||||
"archive-format": "darwin",
|
||||
"binary-format": "mach-o",
|
||||
"crt-objects-fallback": "false",
|
||||
"data-layout": "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-n32:64-S128-Fn32",
|
||||
"debuginfo-kind": "dwarf",
|
||||
"default-uwtable": true,
|
||||
"disable-redzone": true,
|
||||
"emit-debug-gdb-scripts": false,
|
||||
"features": "+v8a,+strict-align,+neon",
|
||||
"frame-pointer": "non-leaf",
|
||||
"function-sections": false,
|
||||
"linker-flavor": "gnu-lld",
|
||||
"lld-flavor": "darwin",
|
||||
"llvm-target": "arm64-apple-macosx",
|
||||
"max-atomic-width": 128,
|
||||
"metadata": {
|
||||
"description": "aarch64 Mach-O target for NuttX sim on macOS",
|
||||
"host_tools": false,
|
||||
"std": true,
|
||||
"tier": 3
|
||||
},
|
||||
"os": "nuttx",
|
||||
"panic-strategy": "abort",
|
||||
"split-debuginfo": "off",
|
||||
"stack-probes": {
|
||||
"kind": "inline"
|
||||
},
|
||||
"target-family": [
|
||||
"unix"
|
||||
],
|
||||
"target-pointer-width": 64,
|
||||
"vendor": "unknown"
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue