pouët.net

gas bin-lumps .int

category: general [glöplog]
 
For binary lumps in my executables for gnu c I've been doing this:

pants.h:

extern unsigned char *pants_lump;

pants.s:

.section .rodata
.align 4
.globl pants_lump

pants_lump:
.int pants_data

pants_data:
.incbin "pants.bin"

So, here's my question. ".int" works just fine for 32-bit systems. For 64-bit systems what's the proper way to dump a pointer? Looking at the gas manual I don't find anything like ".lea" or anything universal. What should I use?
added on the 2011-01-30 08:55:30 by sigflup sigflup
.long, maybe?
added on the 2011-01-30 11:21:56 by Gargaj Gargaj
pants.off
added on the 2011-01-30 11:24:08 by Puryx Puryx
1. You don't have to store that int. The following should work - didn't try it.
Code: .section .rodata .align 4 .globl pants_lump pants_lump: .incbin "pants.bin


pants.h:
Code: extern const unsigned char pants_lump[];

Should do it.

2. Maybe you want to try this
Code: las@jumper$ ld -r -b binary -o incbin.o MyFile.Foo las@jumper$ objdump --syms incbin.o incbin.o: file format elf64-x86-64 SYMBOL TABLE: 0000000000000000 l d .data 0000000000000000 .data 0000000000000000 g .data 0000000000000000 _binary_MyFile_Foo_start 000000000000001a g *ABS* 0000000000000000 _binary_MyFile_Foo_size 000000000000001a g .data 0000000000000000 _binary_MyFile_Foo_end $


Now you can put the following in your header file
Code: extern const char _binary_MyFile_Foo_start[]; extern int _binary_MyFile_Foo_size[]; extern const char _binary_MyFile_Foo_end[];


It will work on x86_64 and x86
Isn't that exactly what one wants?

3. PLEASE USE NASM.

4. Why don't you just use -m32 and everything will be fine? :D
added on the 2011-01-30 11:26:15 by las las
@las [] is another name for *

@gargaj yes but there has to be some universal directive that I can use.

Going to bed, I'll read the manual more tomorrow.

@las your symbol tables lumps looks interesting. I'll get back to it tomorrow
added on the 2011-01-30 13:02:33 by sigflup sigflup
Quote:
@las [] is another name for *

Nope that's just not correct. Just try it.

With:
Code: extern const char* _binary;


Code: gcc -Wall -Wextra -O3 -std=c99 -D_GNU_SOURCE=1 -m32 -c main.c gcc -o main1 -m32 main.o incbin.o Segmentation fault


Now with:
Code: extern const char _binary[];


Code: gcc -Wall -Wextra -O3 -std=c99 -D_GNU_SOURCE=1 -m32 -c main.c gcc -o main1 -m32 main.o incbin.o asdf


incbin.asm:
Code: BITS 32 global _binary section .data _binary: incbin "bin",0,4


bin:
Code: asdf
added on the 2011-01-30 13:28:20 by las las
Correction for the "now you can put the following..."-part
Code: extern const char _binary_MyFile_Foo_start[]; extern int _binary_MyFile_Foo_size; extern const char _binary_MyFile_Foo_end[];
added on the 2011-01-30 13:29:54 by las las
@las no you're right. I guess that's it then. thanks
added on the 2011-01-30 20:27:31 by sigflup sigflup
no problem :)
added on the 2011-01-30 21:06:30 by las las

login