在我的计算机上编译以下程序时,它会输出预期值:
fn main() {
let number = 42;
println!("number is {}", number);
}
数字是42
当为armv5te交叉编译并在目标上运行时,它会输出以下结果:
数字是14
我认为Display
i32
的实施工作没有按预期进行。特别是,似乎打印的字符采用以下数组中的错误索引(在libcore/fmt/num.rs中找到):
const DEC_DIGITS_LUT: &'static[u8] =
b"0001020304050607080910111213141516171819\
2021222324252627282930313233343536373839\
4041424344454647484950515253545556575859\
6061626364656667686970717273747576777879\
8081828384858687888990919293949596979899";
显示的两位数字在桌面上以左边1个字节的偏移量与右边的位置相比较。我通过测试一些其他数字(例如10 - > 91,11 - > 01)验证了这个假设。
其他格式({:b}
,{:o}
,{:x}
)都会在我的计算机和目标上提供预期的结果。
我正在使用Rust的自编译版本(1.13.0,2c6933acc 2016-11-07),以便在我的计算机上成功进行测试,并在我的ARM设备上进行不成功的测试。以下是我必须做的修改的差异:
diff --git a/mk/cfg/arm-unknown-linux-gnueabi.mk b/mk/cfg/arm-unknown-linux-gnueabi.mk
index f66ad04..b9e4157 100644
--- a/mk/cfg/arm-unknown-linux-gnueabi.mk
+++ b/mk/cfg/arm-unknown-linux-gnueabi.mk
@@ -1,5 +1,5 @@
# arm-unknown-linux-gnueabi configuration
-CROSS_PREFIX_arm-unknown-linux-gnueabi=arm-linux-gnueabi-
+CROSS_PREFIX_arm-unknown-linux-gnueabi=arm-unknown-linux-uclibcgnueabi-
CC_arm-unknown-linux-gnueabi=gcc
CXX_arm-unknown-linux-gnueabi=g++
CPP_arm-unknown-linux-gnueabi=gcc -E
@@ -8,8 +8,8 @@ CFG_LIB_NAME_arm-unknown-linux-gnueabi=lib$(1).so
CFG_STATIC_LIB_NAME_arm-unknown-linux-gnueabi=lib$(1).a
CFG_LIB_GLOB_arm-unknown-linux-gnueabi=lib$(1)-*.so
CFG_LIB_DSYM_GLOB_arm-unknown-linux-gnueabi=lib$(1)-*.dylib.dSYM
-CFG_JEMALLOC_CFLAGS_arm-unknown-linux-gnueabi := -Darm -mfloat-abi=soft $(CFLAGS) -march=armv6 -marm
-CFG_GCCISH_CFLAGS_arm-unknown-linux-gnueabi := -Wall -g -fPIC -Darm -mfloat-abi=soft $(CFLAGS) -march=armv6 -marm
+CFG_JEMALLOC_CFLAGS_arm-unknown-linux-gnueabi := -Darm -mfloat-abi=soft $(CFLAGS) -fno-stack-protector -march=armv5te -mtune=arm926ej-s
+CFG_GCCISH_CFLAGS_arm-unknown-linux-gnueabi := -Wall -g -fPIC -Darm -mfloat-abi=soft $(CFLAGS) -fno-stack-protector -march=armv5te -mtune=arm926ej-s
CFG_GCCISH_CXXFLAGS_arm-unknown-linux-gnueabi := -fno-rtti $(CXXFLAGS)
CFG_GCCISH_LINK_FLAGS_arm-unknown-linux-gnueabi := -shared -fPIC -g
CFG_GCCISH_DEF_FLAG_arm-unknown-linux-gnueabi := -Wl,--export-dynamic,--dynamic-list=
diff --git a/src/librustc_back/target/arm_unknown_linux_gnueabi.rs b/src/librustc_back/target/arm_unknown_linux_gnueabi.rs
index e666a84..8af2596 100644
--- a/src/librustc_back/target/arm_unknown_linux_gnueabi.rs
+++ b/src/librustc_back/target/arm_unknown_linux_gnueabi.rs
@@ -24,7 +24,7 @@ pub fn target() -> TargetResult {
target_vendor: "unknown".to_string(),
options: TargetOptions {
- features: "+v6".to_string(),
+ features: "+v5te".to_string(),
.. base
},
})
答案 0 :(得分:5)
我终于找到了解决这个问题的方法!
问题是LLVM没有正确配置,并且正在生成执行未对齐访问的代码。为了解决这个问题,我在src / librustc_back / target / arm_unknown_linux_gnueabi.rs中添加了strict-align
功能标志。
这是我必须做的所有修改的最终差异:
diff --git a/mk/cfg/arm-unknown-linux-gnueabi.mk b/mk/cfg/arm-unknown-linux-gnueabi.mk
index f66ad04..b9e4157 100644
--- a/mk/cfg/arm-unknown-linux-gnueabi.mk
+++ b/mk/cfg/arm-unknown-linux-gnueabi.mk
@@ -1,5 +1,5 @@
# arm-unknown-linux-gnueabi configuration
-CROSS_PREFIX_arm-unknown-linux-gnueabi=arm-linux-gnueabi-
+CROSS_PREFIX_arm-unknown-linux-gnueabi=arm-unknown-linux-uclibcgnueabi-
CC_arm-unknown-linux-gnueabi=gcc
CXX_arm-unknown-linux-gnueabi=g++
CPP_arm-unknown-linux-gnueabi=gcc -E
@@ -8,8 +8,8 @@ CFG_LIB_NAME_arm-unknown-linux-gnueabi=lib$(1).so
CFG_STATIC_LIB_NAME_arm-unknown-linux-gnueabi=lib$(1).a
CFG_LIB_GLOB_arm-unknown-linux-gnueabi=lib$(1)-*.so
CFG_LIB_DSYM_GLOB_arm-unknown-linux-gnueabi=lib$(1)-*.dylib.dSYM
-CFG_JEMALLOC_CFLAGS_arm-unknown-linux-gnueabi := -D__arm__ -mfloat-abi=soft $(CFLAGS) -march=armv6 -marm
-CFG_GCCISH_CFLAGS_arm-unknown-linux-gnueabi := -Wall -g -fPIC -D__arm__ -mfloat-abi=soft $(CFLAGS) -march=armv6 -marm
+CFG_JEMALLOC_CFLAGS_arm-unknown-linux-gnueabi := -D__arm__ -mfloat-abi=soft $(CFLAGS) -fno-stack-protector -march=armv5te -mtune=arm926ej-s
+CFG_GCCISH_CFLAGS_arm-unknown-linux-gnueabi := -Wall -g -fPIC -D__arm__ -mfloat-abi=soft $(CFLAGS) -fno-stack-protector -march=armv5te -mtune=arm926ej-s
CFG_GCCISH_CXXFLAGS_arm-unknown-linux-gnueabi := -fno-rtti $(CXXFLAGS)
CFG_GCCISH_LINK_FLAGS_arm-unknown-linux-gnueabi := -shared -fPIC -g
CFG_GCCISH_DEF_FLAG_arm-unknown-linux-gnueabi := -Wl,--export-dynamic,--dynamic-list=
diff --git a/src/librustc_back/target/arm_unknown_linux_gnueabi.rs b/src/librustc_back/target/arm_unknown_linux_gnueabi.rs
index e666a84..551bba0 100644
--- a/src/librustc_back/target/arm_unknown_linux_gnueabi.rs
+++ b/src/librustc_back/target/arm_unknown_linux_gnueabi.rs
@@ -24,7 +24,7 @@ pub fn target() -> TargetResult {
target_vendor: "unknown".to_string(),
options: TargetOptions {
- features: "+v6".to_string(),
+ features: "+v5te,+strict-align".to_string(),
.. base
},
})