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?
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?
.long, maybe?
pants.off
1. You don't have to store that int. The following should work - didn't try it.
pants.h:
Should do it.
2. Maybe you want to try this
Now you can put the following in your header file
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
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
@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
@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
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
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[];
@las no you're right. I guess that's it then. thanks
no problem :)