0

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?

1 Answer 1

2

You need to restore the section back to .text at the end of the inline asm. You could use .pushsection and .popsection todo so.

Sign up to request clarification or add additional context in comments.

1 Comment

Added .text at the end of the macro for _WIN32 for now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.