I wrote a simple helloworld in assembler under debian linux
; Define variables in the data section
SECTION .data
hello: db 'Hello world!',10
helloLen: equ $-hello
; Code goes in the text section
SECTION .text
GLOBAL _start
_start:
mov eax,4 ; 'write' system call = 4
mov ebx,1 ; file descriptor 1 = STDOUT
mov ecx,hello ; string to write
mov edx,helloLen ; length of string to write
int 80h ; call the kernel
; Terminate program
mov eax,1 ; 'exit' system call
mov ebx,0 ; exit with error code 0
int 80h ; call the kernel
Then compile
nasm -f elf64 hello.asm -o hello.o
ld -o hello hello.o.
and got a 9048 byte binary. Then I changed two lines in the code: from.data to.DATA and.text to.TEXT
SECTION .DATA
SECTION .TEXT
and got a 4856 byte binary. Change them to
SECTION .dAtA
SECTION .TeXt
got a 4856 byte binary too.
NASM is declared to be a case-insensitive compiler. What is the difference then?
You're free to use whatever names you like for ELF sections, but if you don't use standard names, it becomes your responsibility to specify the section flags. (If you use standard names, you get to take advantage of default flag settings for those names.) Section names are case-sensitive, and .data
and .text
are known to NASM. .DATA
, .dAta
, etc. are not, and there is nothing which distinguishes these sections from each other, allowing ld
to combine them into a single segment.
That automatically makes your executable smaller. With the standard flags for .text
and .data
, one of those is read-only and the other is read-write, which means that they cannot be placed into the same memory page. In your example program, both sections are quite small, so they could fit in a single memory page. Thus, using non-standard names makes your executable one page smaller, but one of the sections will have incorrect writability.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.