I'm using the esp32ulp assembler on .S files. I have been experiencing issues when using macro's.
esp32ulp-elf-as.exe does not produce valid .o files on macro's when processing the .pS file when it is big or a bit complex. The problems is that it will not increment correctly the instruction counter inside the macro.
For example, here is the code that fails (extract from the .d file):
Code: Select all
114 nrf24IsConnected:
115 00b0 0000501A readRegister 0x03
115 01008072
115 35000072
115 01008072
115 0D000068
115 1F002072
115 00000080
115 F10F8072
115 01008072
115 0D000068
115 1F002072
115 00000080
115 0105501A
116 00e4 01000C82 jumpr nrf24IsNotConnected, 1, LT
117 00e8 04000B82 jumpr nrf24IsNotConnected, 4, GE
118 00ec 10008072 move r0, 1
Code: Select all
.macro readRegister reg
beginTransactionSpi
move r1, R_REGISTER
add r1, r1, \reg
move r1, ret1\@[/b] // here we reference the address ret1
st r1,r3,0
sub r3,r3,1
jump SPI_Trans_Byte // here we reference the address SPI_Trans_Byte
ret1\@:
move r1, 0xFF
move r1, ret2\@ // here we reference the address ret2
st r1,r3,0
sub r3,r3,1
jump SPI_Trans_Byte // here we reference the address SPI_Trans_Byte
ret2\@:
endTransactionSpi
.endm
When dumping the relocation section in the .o file produced by the assembler, it can be noticed that all relocation information corresponding to the code inside the macro (lines 0xB0) are wrongly assigned to the same location (aka 0xB0), which is the address of the first instruction of the macro :
Code: Select all
$ esp32ulp-elf-readelf -r a.out
Section de r▒adressage '.rela.text' ▒ l'adresse de d▒calage 0xce8 contient 111 entr▒es:
D▒calage Info Type Val.-sym Noms-symb + Addenda
00000024 00000105 R_ESP32ULP_ALUI 00000000 .text + 34
00000030 00002f01 R_ESP32ULP_RIMM16 00000000 SPI_Init + 0
00000050 00000105 R_ESP32ULP_ALUI 00000000 .text + 60
0000005c 00003101 R_ESP32ULP_RIMM16 00000000 SPI_Trans_Byte + 0
00000064 00000105 R_ESP32ULP_ALUI 00000000 .text + 74
00000070 00000105 R_ESP32ULP_ALUI 00000000 .text + 74
00000074 00003101 R_ESP32ULP_RIMM16 00000000 SPI_Trans_Byte + 0
00000090 00000105 R_ESP32ULP_ALUI 00000000 .text + a0
0000009c 00003101 R_ESP32ULP_RIMM16 00000000 SPI_Trans_Byte + 0
000000b0 00000105 R_ESP32ULP_ALUI 00000000 .text + cc <== address b0 is wrong
000000b0 00003101 R_ESP32ULP_RIMM16 00000000 SPI_Trans_Byte + 0 <== address b0 is wrong
000000b0 00000105 R_ESP32ULP_ALUI 00000000 .text + e0 <== address b0 is wrong
000000b0 00003101 R_ESP32ULP_RIMM16 00000000 SPI_Trans_Byte + 0[/b] <== address b0 is wrong
000000e4 0000010f R_ESP32ULP_JUMPR_ 00000000 .text + fc
000000e8 0000010f R_ESP32ULP_JUMPR_ 00000000 .text + fc
00000110 00000105 R_ESP32ULP_ALUI 00000000 .text + 12c
00000110 00003101 R_ESP32ULP_RIMM16 00000000 SPI_Trans_Byte + 0
00000110 00000105 R_ESP32ULP_ALUI 00000000 .text + 140
00000110 00003101 R_ESP32ULP_RIMM16 00000000 SPI_Trans_Byte + 0
00000148 00000105 R_ESP32ULP_ALUI 00000000 .text + 164
00000148 00003101 R_ESP32ULP_RIMM16 00000000 SPI_Trans_Byte + 0
00000148 00000105 R_ESP32ULP_ALUI 00000000 .text + 178
00000148 00003101 R_ESP32ULP_RIMM16 00000000 SPI_Trans_Byte + 0
00000188 00000105 R_ESP32ULP_ALUI 00000000 .text + 1a4
00000188 00003101 R_ESP32ULP_RIMM16 00000000 SPI_Trans_Byte + 0
I can solve the issue in the source code of the binutils-esp32ulp (I have recompiled the source code but the issue is still there) but I have no idea where macros are handled. Any idea ?
I have tried other methods like replacing .macro by #define but runs into the same trouble.