I want to append a string to a macro argument in gcc assembler. Here is what I have currently:
The following macro to embed a file in my code which works just fine:
.macro add_resource resource_name, file_name
.global \resource_name
.type \resource_name, @object
.balign 4
\resource_name:
.incbin "\file_name"
end_\resource_name:
.global size_\resource_name
.type size_\resource_name, @object
.balign 4
size_\resource_name:
.int end_\resource_name - \resource_name
.endm
.section .rodata
add_resource icon, "icon.png"
usage:
#include <stdio.h>
extern unsigned char icon[];
extern unsigned int size_icon;
int main() {
printf("magic bytes: %.3s, size: %u", icon+1, size_icon);
return 0;
}
running nm
on produced executable:
0000000000f99b9d r end_icon
0000000000002020 R icon
0000000000f99ba0 R size_icon
the program prints "magic bytes: PNG, size: 16350077".
But the name "size_icon" looks awful, and i want to append the "size", instead of prepending it, which would make it "icon_size". But i don't know how to do that and couldn't find anything useful in documentation. Can anyone help?
As Jester pointed out, I overlooked the \()
syntax. I can just write
\resource_name\()_size
and it will generate "image_size" identifier.