On Fri, 12 Oct 2018, Mikola Akbal wrote:
> Sorry, i apply additional information to previous bug report. Bug is the
> same.
>
> I took "Hello World!" assembler example from here:
<a page which says "These examples are only for operating systems using
the Linux kernel and an x86-64 processor, however.">
>
> I try to assemble it, but i receive error.
>
> "gcc -c hello.s" works successful. "ld hello.o" gives error:
>
> ld: hello.o: relocation R_X86_64_32S against `a local symbol' can not be
> used when making a shared object; recompile with -fPIC
> hello.o: could not read symbols: Bad value
>
> I attached "hello.s" file to e-mail. OpenBSD version: 6.3 amd64.
> "gcc -c -fPIC hello.s" does not help. "dmesg.boot"'s are attached.
By default, OpenBSD expects programs to be compiled/written to be PIE
(position-independent executables). The C compiler generates PIE/PIC
assembly output by default, but if you hand-write assembly you must do
that work yourself. You can see what that means by comparing the
assembler output from compiling a C program with
cc -S -fno-pie whatever.c
vs
cc -S whatever.c
You'll see, for example, that global variables are referenced via
%rip-relative addressing instead of with absolute addresses.
If you _must_ have a non-PIE program (perhaps on your way to understanding
how to write PIE assembly), you can link a non-PIE program by passing ld
the -nopie option.
Philip Guenther