I have a very simple assembly program:
global start
section .text
start:
mov r12, string_2
section .data
string_1: db 'string one',0
string_2: db 'string two',0
I assemble and link it on my mac with nasm:
nasm -fmacho64 -o string.o ./string.x64 && ld -o string ./string.o
And then debug it with lldb string
.
What I see is that the address loaded into r12
is not the actual address that string_2
exists at. string_1
is placed at address 0x2000
, with string_2
right after it, beginning at address 0x200b
. But the address loaded into r12
is 0x2016
. How do I load the actual address of string_2
?
In case it's relevant, these are the versions of the programs I'm using:
$ nasm -v
NASM version 2.13.03 compiled on Feb 8 2018
$ ld -v
@(#)PROGRAM:ld PROJECT:ld64-351.8
configured to support archs: armv6 armv7 armv7s arm64 i386 x86_64 x86_64h armv6m armv7k armv7m armv7em (tvOS)
LTO support using: LLVM version 9.1.0, (clang-902.0.39.1) (static support for 21, runtime is 21)
TAPI support using: Apple TAPI version 9.1.0 (tapi-902.0.9)
$ lldb -v
lldb-902.0.79.2
Swift-4.1