Please help. GNU As syntax for pointers with ANSI C binding in platform independent way.
Oleksandr Gavenko
gavenko@bifit.com.ua
Wed Nov 10 17:25:00 GMT 2010
More information about the Binutils mailing list
Wed Nov 10 17:25:00 GMT 2010
- Previous message (by thread): New Finnish PO file for 'bfd' (version 2.20.90)
- Next message (by thread): Please help. GNU As syntax for pointers with ANSI C binding in platform independent way.
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
I want include binary data in executable.
For this purpose I use such techniques (from my Makefile):
%.o %.h: %.bin
echo "extern const char *$*;" >$*.h
echo '.text; .global $*; $*_data:; .incbin "$*.bin"; $*:; .int
$*_data;' | gcc -x assembler -o $*.o -c -
This cryptic code equivalents to .S file (when 'str.bin' processed):
.text
.global str
str_data:
.incbin "str.bin"
str:
.int str_data # XXX .int or .quad ???
To access the data from str.bin I use in .c:
================================================================
#include "str.h" /* here placed: extern const char *str; */
int foo() {
printf(str);
}
================================================================
In case of 32-bit platform I need wrote '.int', in case of
64-bit platform I need wrote '.quad' in assembler.
To work around I can use #if/#define and preprocess output.
But this seems ugly. Is there portable syntax?
Also I don't understand way I can not directly point str_data in
printf() call. Why I need wrote '&' before 'str_data' in .c:
================================================================
extern const char str_data; /* For type resolving I don't declare
pointer */
int foo() {
printf(&str_data); /* because C compiler think that str_data is
data itself, do not point to it! */
}
================================================================
to satisfy ANSI C types and make executable correct working?
To get ability use natural C style code I use another symbol
'str' that point to actual data in 'str_data':
================================================================
str:
.int str_data # XXX .int or .quad ???
================================================================
so in .c file can place:
================================================================
extern const char *str; /* Real pointer. */
...
printf(str); /* No ugly dereferencing. */
================================================================
So questions:
1) is correctly I declare pointer to data from .S for C sources or
there are exist another true way?
2) can I make pointer in .S in portable way (to avoid use of .int/.quad)?
- Previous message (by thread): New Finnish PO file for 'bfd' (version 2.20.90)
- Next message (by thread): Please help. GNU As syntax for pointers with ANSI C binding in platform independent way.
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Binutils mailing list