ps4-payload-sdk icon indicating copy to clipboard operation
ps4-payload-sdk copied to clipboard

Cannot compile libPS4/source/syscall.s

Open Nathaniel-Wu opened this issue 8 years ago • 7 comments

source/syscall.s:20:7: error: cannot use base register with variable reference
 call syscall_rop[rip]
      ^
source/syscall.s:25:17: error: cannot use base register with variable reference
  cmp qword ptr __error[rip], 0
                ^
source/syscall.s:28:8: error: cannot use base register with variable reference
  call __error[rip]
       ^

I'm trying to compile it under macOS, is this related to the problem? I know very little about x86 assembly.

Nathaniel-Wu avatar Apr 10 '17 12:04 Nathaniel-Wu

Strange, the point of using [rip] in this case is to force a relative reference to the memory. I'm guessing it's LLVM spitting out this error?

idc avatar Apr 19 '17 09:04 idc

Can reproduce relatively similarly on MSYS2

pacman -Syuu
pacman -S git tar bzip2 make llvm binutils
source shell mingw64
pacman -S clang
git clone https://github.com/idc/PS4-SDK.git PS4-SDK--idc && pushd PS4-SDK--idc
sed -i s/gcc/clang/ libPS4/Makefile
make -C libPS4
source/syscall.s:7:22: error: unknown flag
.section .sc_rop,"wb"
                     ^
source/syscall.s:18:18: error: unexpected token in argument list
        call syscall_rop[rip]
                        ^
source/syscall.s:23:24: error: unexpected token in argument list
  cmp qword ptr __error[rip], 0
                       ^
source/syscall.s:26:15: error: unexpected token in argument list
  call __error[rip]
              ^

(side note: is the first error because mac uses a different format, macho if I remember correctly?)

$ clang --version
clang version 3.8.0 (/repo/sources/clang 1d5b05f1ef9d1b9889ddb5ad946944f224a7ba88) (/repo/sources/llvm 2aebced35905eb3891eba484e4d1902cf7399558)
Target: x86_64-pc-msys
Thread model: posix
InstalledDir: /usr/bin

Do you think using something like

lea rax, [syscall_rop + rip]
call rax

would work around this?

mchubby avatar May 03 '17 21:05 mchubby

Same issue MacOS with clang-3.9

mbpdesofiane:libPS4 theorywrong$ clang --version clang version 3.9.0 (http://llvm.org/git/clang.git ef08168fd27c12796280b03994ae9bbb53ed2953) (http://llvm.org/git/llvm.git 73b2bb0c65a69efe10930d227025005b8c819642) Target: x86_64-scei-ps4 Thread model: posix InstalledDir: /toolchain/bin

clang -c -o build/syscall.o source/syscall.s -nostartfiles -nostdlib -march=btver2 -mtune=btver2 clang-3.9: warning: argument unused during compilation: '-nostartfiles' clang-3.9: warning: argument unused during compilation: '-mtune=btver2' source/syscall.s:18:18: error: unexpected token in argument list call syscall_rop[rip] ^ source/syscall.s:23:24: error: unexpected token in argument list cmp qword ptr __error[rip], 0 ^ source/syscall.s:26:15: error: unexpected token in argument list call __error[rip] ^ make: *** [build/syscall.o] Error 1

ghost avatar Dec 27 '17 22:12 ghost

Still have not figured out how to enable RIP-addressing in clang. You can try removing the [rip] and see if it builds and executes properly. However, RIP addressing is necessary with gcc as it will try to refer to syscall_rop and __error by absolute addressing (which is wrong).

idc avatar Dec 27 '17 23:12 idc

On Ubuntu Bash in Windows, it shows:

gcc -c -o build/syscall.o source/syscall.s -nostartfiles -nostdlib -march=btver2 -mtune=btver2 source/syscall.s: Assembler messages: source/syscall.s:7: Fatal error: bad .section directive: want a,l,w,x,M,S,G,T in string Makefile:24: recipe for target 'build/syscall.o' failed make: *** [build/syscall.o] Error 1

urherenow avatar Jan 18 '18 13:01 urherenow

Edit source/syscalls.s uncomment the write line and comment the wb line. .section .sc_rop,"w" #.section .sc_rop,"wb"

segobi avatar Jan 18 '18 13:01 segobi

Thanks! That did the trick!

urherenow avatar Jan 18 '18 14:01 urherenow