2017-05-01 55 views
1

要解决a Rust compiler bug in the AVR backend,我已经标记了很多我的功能,作为#[inline(always)],只需添加注释,直到足够的情况下优化等会激发我不再遇到问题。链接失败,“重定位被截断为适合”与积极内联

然而,这些注解,现在连接失败,有很多relocation truncated to fit消息:

target/avr-atmega328p/release/deps/chip8_avr-41c427b8d446a439.o: In function `LBB5_18': 
chip8_avr.cgu-0.rs:(.text.main+0x432): relocation truncated to fit: R_AVR_7_PCREL against `no symbol' 
target/avr-atmega328p/release/deps/chip8_avr-41c427b8d446a439.o: In function `LBB5_23': 
chip8_avr.cgu-0.rs:(.text.main+0x45c): relocation truncated to fit: R_AVR_7_PCREL against `no symbol' 
target/avr-atmega328p/release/deps/chip8_avr-41c427b8d446a439.o: In function `LBB5_31': 
chip8_avr.cgu-0.rs:(.text.main+0x4ae): relocation truncated to fit: R_AVR_7_PCREL against `no symbol' 
target/avr-atmega328p/release/deps/chip8_avr-41c427b8d446a439.o: In function `LBB5_34': 
chip8_avr.cgu-0.rs:(.text.main+0x4d2): relocation truncated to fit: R_AVR_7_PCREL against `no symbol' 
target/avr-atmega328p/release/deps/chip8_avr-41c427b8d446a439.o: In function `LBB5_146': 
chip8_avr.cgu-0.rs:(.text.main+0x58a): relocation truncated to fit: R_AVR_7_PCREL against `no symbol' 
chip8_avr.cgu-0.rs:(.text.main+0x58e): relocation truncated to fit: R_AVR_7_PCREL against `no symbol' 
chip8_avr.cgu-0.rs:(.text.main+0x592): relocation truncated to fit: R_AVR_7_PCREL against `no symbol' 
target/avr-atmega328p/release/deps/chip8_avr-41c427b8d446a439.o: In function `LBB5_153': 
chip8_avr.cgu-0.rs:(.text.main+0x59a): relocation truncated to fit: R_AVR_7_PCREL against `no symbol' 
chip8_avr.cgu-0.rs:(.text.main+0x59e): relocation truncated to fit: R_AVR_7_PCREL against `no symbol' 
chip8_avr.cgu-0.rs:(.text.main+0x5a6): relocation truncated to fit: R_AVR_7_PCREL against `no symbol' 
chip8_avr.cgu-0.rs:(.text.main+0x5aa): additional relocation overflows omitted from the output 
collect2: error: ld returned 1 exit status 

This SO answer意味着大内部功能跃变的东西,编译器需要进行的准备。什么是Rust的等效设置?

回答

0

在仔细研究反汇编后,事实证明这些重定位目标都在分支指令的偏移量中,而不是(短)跳转;例如在0x08的:

00000000 <_ZN12chip8_engine7opcodes6decode17haab3c6c935229a6aE>: 
    0: e8 2f   mov  r30, r24 
    2: f9 2f   mov  r31, r25 
    4: 80 e0   ldi  r24, 0x00  ; 0 
    6: 61 30   cpi  r22, 0x01  ; 1 
    8: 01 f4   brne .+0    ; 0xa <_ZN12chip8_engine7opcodes6decode17haab3c6c935229a6aE+0xa> 
    a: 81 83   std  Z+1, r24  ; 0x01 
    c: 82 83   std  Z+2, r24  ; 0x02 
    e: 81 e0   ldi  r24, 0x01  ; 1 

00000010 <LBB0_2>: 
    10: 80 83   st  Z, r24 
    12: 08 95   ret 

锈编译器的AVR叉目前产生与空(.+0)偏移量这些分支,然后尝试使用连接体填充它们在对于足够大的功能,这些帧内函数偏移即可。变得比适合单个分支指令的更大。

我在Rust的AVR fork中有reported this as a compiler bug。出现的一个可能的解决方案是让链接器生成一个两步跳转(跳转跳转)的偏移量不适合的情况;另一种是完全不使用链接器:由于所讨论的分支是内部函数,所以在编译时应该知道相对地址,允许在需要时生成两步分支。