I tried to use this trick together to embed a resource into an executable file:
#define INCLUDE_BINARY(identifier,filename) \
asm("\t.data\n" \
"\t.local " #identifier "_begin\n" \
"\t.type " #identifier "_begin, @object\n" \
"\t.align 16\n" \
#identifier "_begin:\n" \
"\t.incbin \"" filename "\"\n\n" \
\
"\t.local " #identifier "_end\n" \
"\t.type " #identifier "_end, @object\n" \
"\t.align 1\n" \
#identifier "_end:\n" \
"\t.byte 0\n"); \
\
extern uint8_t identifier##_begin[];\
extern const uint8_t identifier##_end[]
So that
#include <herbs/include_binary/include_binary.h>
#include <herbs/main/main.h>
#include <cstdio>
INCLUDE_BINARY(source,__FILE__);
int MAIN(int argc,charsys_t* argv[])
{
const uint8_t* begin=source_begin;
while(begin!=source_end)
{
putchar(*begin);
++begin;
}
return 0;
}
will print itself. It works fine until I enable debug symbol generation. Then I get errors:
/tmp/ccCfX7kc.s:103: Error: can't resolve `.data' {.data section} - `.Ltext0' {.text section}
I guess the reason of failure is that -g adds stuff at the beginning of file:
.text
.Ltext0:
Is there a way to add global symbols using inline assembly that does not interfere with debugging? Is asm undefined outside a function body?