0

I try to convert this assembly file : https://github.com/gvanas/KeccakCodePackage/blob/master/SnP/KeccakF-1600/OptimizedAsmX86-64/KeccakF-1600-x86-64-gas.s into apple syntax. (old syntax)

I replace .eq by #define, .global by .globl, remove .type, .size.

There is some errors again (i use clang) :

1 --

error: invalid operand for instruction subq *25, %rsp (the instruction is : subq $8*25, %rsp )

2 --

error in backend: 32-bit absolute addressing is not supported in 64-bit mode :

movb KeccakPowerOf2(arg2), %al

xorb %al, (arg1)

with

#define arg1 %rdi

#define arg2 %rsi

and

KeccakPowerOf2: .byte 1, 2, 4, 8, 16, 32, 64, 128

3 --

error in backend: 32-bit absolute addressing is not supported in 64-bit mode

leaq KeccakLaneComplementTable, arg5

with

#define arg5 %r8

and

`KeccakLaneComplementTable:

.quad   0
.quad   0xFFFFFFFFFFFFFFFF  //  1 be
.quad   0xFFFFFFFFFFFFFFFF  //  2 bi
.quad   0
.quad   0

.quad   0
.quad   0
.quad   0
.quad   0xFFFFFFFFFFFFFFFF  //  8 go
.quad   0

.quad   0
.quad   0
.quad   0xFFFFFFFFFFFFFFFF  // 12 ki
.quad   0
.quad   0

.quad   0
.quad   0
.quad   0xFFFFFFFFFFFFFFFF  // 17 mi
.quad   0
.quad   0

.quad   0xFFFFFFFFFFFFFFFF  // 20 sa
.quad   0
.quad   0
.quad   0
.quad   0`

Any ideas ?

Thank you

Stephane
  • 391
  • 1
  • 2
  • 13

1 Answers1

0

OS X linking / relocation doesn't support 32bit absolute addressing. Use RIP relative.

leaq    KeccakLaneComplementTable(%rip), arg5

For 2, you probably need to load the base address with a separate instruction, before you index it with movb. Any spare register will do. I'll use %rax for example, since you're about to load into it anyway. If you can spare a register, you can hoist the lea out and do it only once at the start.

lea     KeccakPowerOf2(%rip), %rax
movb    (%rax,arg2), %al
xorb    %al, (arg1)

Or if the offset between KeccakLaneComplementTable and KeccakPowerOf2 is fixed, and that address is kept around permanently, then you can do

; if arg5 still has the address of KeccakLaneComplementTable
movb    KeccakPowerOf2 - KeccakLaneComplementTable(arg5, arg2), %al
xorb    %al, (arg1)

KeccakPowerOf2 - KeccakLaneComplementTable should be an assemble-time constant, and doesn't have to wait for link-time, so it's safe even on OS X. The idea is that [KeccakPowerOf2 - KeccakLaneComplementTable + arg5] is KeccakPowerOf2, so [KeccakPowerOf2 + arg2] becomes [KeccakPowerOf2 - KeccakLaneComplementTable + arg5 + arg2 ].


For 1, IDK why subq $8*25, %rsp wouldn't assemble. It assembles fine with GNU binutils 2.25.1. Maybe try $(8*25)? Or if you can't get that to work, just substitute the single number $200 and put 200 = 8*25 in a comment.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847