Sujet : Re: C23 thoughts and opinions
De : already5chosen (at) *nospam* yahoo.com (Michael S)
Groupes : comp.lang.cDate : 30. May 2024, 15:08:36
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20240530170836.00005fa0@yahoo.com>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
User-Agent : Claws Mail 3.19.1 (GTK+ 2.24.33; x86_64-w64-mingw32)
On Thu, 30 May 2024 14:34:00 +0100
bart <
bc@freeuk.com> wrote:
On 30/05/2024 03:32, Lawrence D'Oliveiro wrote:
On Wed, 29 May 2024 13:58:20 +0200, Bonita Montero wrote:
I've got a small commandline-tool that makes a const'd char
-array from any binary file.
It seems to me it would be more efficient to use objcopy to turn
that binary file directly into an object file with symbols
accessible from C code defining its beginning and ending points.
Then just link it into the executable.
None of my compilers, whether for C or anything else, generate object
files.
However, suppose I wanted to link a file called 'logo.bmp' say, into
my program, which consisted of a file called main.c.
What is the entire process using your suggestion? What do I put into
main.c? Assume the data is represented by a char-array.
extern unsigned char _binary_logo_bmp_start[];
extern unsigned char _binary_logo_bmp_size[];
The first symbol is an array itself.
The seconded symbol contains the length of array. You use it in somewhat
non-intuitive way:
size_t my_size = (size_t)_binary_logo_bmp_size;
Pay attention that I never used this method myself, just took a look at
the output of objcopy with 'objdump -t', so please don't take my words
as a sure thing.
BTW, options in this case are rather simple:
objcopy -I binary -O elf32-little logo.bmp logo_bmp.o
Replace elf32-little with relevant format for your software. However I
am not sure that it would work for none-elf output formats.
This command puts the variable into the section .data. If one wants it
in the different section, e.g. .rwdata then the thing could indeed
become less obvious.