[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Preliminary questions for sponsoring a compiler



Christian Seiler schreef op 2016-07-25 18:14:
On 07/25/2016 02:51 PM, Albert van der Horst wrote:
The problem is: ld is not stable w.r.t. linking pure assembler files.

How so?

$ cat write.s
.text

.global _start
.type   _start, @function

_start:
        mov     $1, %rax
        mov     %rax, %rdi
        lea     str, %rsi
        mov     strsize, %rdx
        syscall
        xor     %rdi, %rdi
        mov     $60, %rax
        syscall

.data
str:
        .string "Hello World!\n"
strsize:
        .quad   .-str
$ gcc -Wall -c -o write.o write.s && ld -o write write.o
$ ./write
Hello World!
$ strace ./write
execve("./write", ["./write"], [/* 58 vars */]) = 0
write(1, "Hello World!\n\0", 14Hello World!
)        = 14
_exit(0)                                = ?
+++ exited with 0 +++
$ cat write-nasm.s
section .text
global  _start

_start:
        mov     rax, 0x1
        mov     rdi, rax
        lea     rsi, [hello]
        mov     rdx, length
        syscall
        xor     edi, edi
        mov     rax, 60
        syscall


section .data
hello   db      'Hello World!', 10, 0
length  equ     $ - hello
$ nasm -f elf64 -o write-nasm.o write-nasm.s
$ ld -o write-nasm write-nasm.o
$ ./write-nasm
Hello World!
$ strace ./write-nasm
execve("./write-nasm", ["./write-nasm"], [/* 58 vars */]) = 0
write(1, "Hello World!\n\0", 14Hello World!
)        = 14
_exit(0)                                = ?
+++ exited with 0 +++

I don't quite get what you mean, I never had any problem with
that.

{Probably going off topic here]
A pure assembler file means full control over section names, their properties (in particular, readable, writable *and* executable) and where they are located. My compilation feature requires a stable layout for the ELF header. gcc and ld are intended for c and if you try to do the things I want, it feels like remote controlling a robot that must drive a car.

I will not bore you with all the details. One detail, .text and .data have predefined properties. Now look how many options ld has. One is appropriate
called -nmagic . It sometimes helps to turn those properties around,
at other times it failed.

By the way write.s gives me  `` bad register name `%rax' ''


Regards,
Christian

Groetjes Albert

--
Suffering is the prerogative of the strong, the weak -- perish.
Albert van der Horst


Reply to: