Re: C23 thoughts and opinions

Liste des GroupesRevenir à cl c 
Sujet : Re: C23 thoughts and opinions
De : bc (at) *nospam* freeuk.com (bart)
Groupes : comp.lang.c
Date : 31. May 2024, 19:03:10
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v3d3ct$2b5sl$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
User-Agent : Mozilla Thunderbird
On 31/05/2024 15:34, Michael S wrote:
On Fri, 31 May 2024 15:04:46 +0100
bart <bc@freeuk.com> wrote:

Can you show the full program and the full process?
 test_objcopy.c:
#include <stdio.h>
 int data1[42] = { 1,2,3 ,4,5};
extern unsigned char _binary_test_bi_start[];
extern unsigned char _binary_test_bi_end[];
extern unsigned char _binary_test_bi_size[];
 extern unsigned char _binary_bin_to_list_c_start[];
extern unsigned char _binary_bin_to_list_c_end[];
extern unsigned char _binary_bin_to_list_c_size[];
 int main()
{
   printf("%-40s %p %zd\n", "_binary_test_bi_start",
     _binary_test_bi_start, (size_t)_binary_test_bi_start);
   printf("%-40s %p %zd\n", "_binary_test_bi_end",
     _binary_test_bi_end, (size_t)_binary_test_bi_end);
   printf("%-40s %p %zd\n", "_binary_test_bi_size",
     _binary_test_bi_size, (size_t)_binary_test_bi_size);
   printf("%-40s %p %zd\n", "_binary_bin_to_list_c_start",
     _binary_bin_to_list_c_start, (size_t)_binary_bin_to_list_c_start);
   printf("%-40s %p %zd\n", "_binary_bin_to_list_c_end",
     _binary_bin_to_list_c_end, (size_t)_binary_bin_to_list_c_end);
   printf("%-40s %p %zd\n", "_binary_bin_to_list_c_size",
     _binary_bin_to_list_c_size, (size_t)_binary_bin_to_list_c_size);
   return 0;
}
 Test files: test.bi and bin_to_list_c.
Conversion to ojects:
objcopy -I binary -O elf64-x86-64 test.bi test_bi.o
objcopy -I binary -O elf64-x86-64 bin_to_list.c test_c.o
 Compilation:
gcc -s -Wall -Oz test_objcopy.c test_bi.o test_c.o
OK, thanks. But I forget to ask what results you got from running the program. Because if I try your code, using hello.c and hello.exe as test binary/source data, I get this output:
_binary_test_bi_start                    00007ff6497620e0 140695771160800
_binary_test_bi_end                      00007ff649762ae0 140695771163360
_binary_test_bi_size                     00007ff509750a00 140690402380288
_binary_bin_to_list_c_start              00007ff649762ae0 140695771163360
_binary_bin_to_list_c_end                00007ff649762b26 140695771163430
_binary_bin_to_list_c_size               00007ff509750046 140690402377798
The sizes should have been 2560 and 70 respectively; those values are bit bigger than that.
However I see that you also have start and end addresses, which sounds a much better way of determining the size. (In that case, what are those *size symbols for?).
So I can put together a working test:
---------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
extern unsigned char _binary_hello_c_start[];
extern unsigned char _binary_hello_c_end[];
char* makestr(char* start, char* end) {
     int length = end-start;
     char* s = malloc(length+1);
     memcpy(s, start, length);
     *(s+length) = 0;
     return s;
}
int main() {
     char* str = makestr(_binary_hello_c_start, _binary_hello_c_end);
     printf("Hello = \n%s", str);
}
---------------------------------
I can build it like this:
---------------------------------
C:\c>mcc -c c
Compiling c.c to c.obj
C:\c>objcopy -I binary -O elf64-x86-64 hello.c hello.obj
C:\c>gcc c.c hello.obj
---------------------------------
And run it like this:
---------------------------------
C:\c>a
Hello =
#include "stdio.h"
int main(void) {
     printf("Hello, World!\n");
}
---------------------------------
Instead of one compiler, here I used two compilers, a tool 'objcopy' (which bizarrely needs to generate ELF format files) and lots of extra ugly code. I also need to disregard whatever the hell _binary_..._size does.
But it works.

Date Sujet#  Auteur
31 May 24 * Re: C23 thoughts and opinions73bart
31 May 24 +* Re: C23 thoughts and opinions67Michael S
31 May 24 i+* Re: C23 thoughts and opinions65Michael S
31 May 24 ii`* Re: C23 thoughts and opinions64Michael S
31 May 24 ii `* Re: C23 thoughts and opinions63bart
31 May 24 ii  `* Re: C23 thoughts and opinions62Michael S
31 May 24 ii   `* Re: C23 thoughts and opinions61bart
31 May 24 ii    +* Re: C23 thoughts and opinions39jak
31 May 24 ii    i+- Re: C23 thoughts and opinions1bart
6 Jun 24 ii    i`* Re: C23 thoughts and opinions37BGB-Alt
7 Jun 24 ii    i +* Re: C23 thoughts and opinions32Lawrence D'Oliveiro
7 Jun 24 ii    i i+* Re: C23 thoughts and opinions15BGB-Alt
8 Jun 24 ii    i ii`* Re: C23 thoughts and opinions14Lawrence D'Oliveiro
8 Jun 24 ii    i ii +* Re: C23 thoughts and opinions11BGB
8 Jun 24 ii    i ii i+- Re: C23 thoughts and opinions1Lawrence D'Oliveiro
13 Jun 24 ii    i ii i`* Re: C23 thoughts and opinions9Bonita Montero
13 Jun 24 ii    i ii i `* Re: C23 thoughts and opinions8BGB
14 Jun 24 ii    i ii i  `* Re: C23 thoughts and opinions7Bonita Montero
14 Jun 24 ii    i ii i   `* Re: C23 thoughts and opinions6BGB
14 Jun 24 ii    i ii i    +* Re: C23 thoughts and opinions2Bonita Montero
14 Jun 24 ii    i ii i    i`- Re: C23 thoughts and opinions1BGB
15 Jun 24 ii    i ii i    `* Re: C23 thoughts and opinions3Lawrence D'Oliveiro
16 Jun 24 ii    i ii i     `* Re: C23 thoughts and opinions2BGB
16 Jun 24 ii    i ii i      `- Re: C23 thoughts and opinions1Lawrence D'Oliveiro
9 Jun 24 ii    i ii +- Re: C23 thoughts and opinions1Lawrence D'Oliveiro
9 Jun 24 ii    i ii `- Re: C23 thoughts and opinions1Michael S
8 Jun 24 ii    i i`* Re: C23 thoughts and opinions16Malcolm McLean
8 Jun 24 ii    i i +* Re: C23 thoughts and opinions14BGB
9 Jun 24 ii    i i i`* Re: C23 thoughts and opinions13Michael S
9 Jun 24 ii    i i i +* Re: C23 thoughts and opinions11bart
9 Jun 24 ii    i i i i`* Re: C23 thoughts and opinions10Michael S
9 Jun 24 ii    i i i i +- Re: C23 thoughts and opinions1Michael S
9 Jun 24 ii    i i i i +* Re: C23 thoughts and opinions7bart
9 Jun 24 ii    i i i i i`* Re: C23 thoughts and opinions6Michael S
9 Jun 24 ii    i i i i i `* Re: C23 thoughts and opinions5bart
9 Jun 24 ii    i i i i i  `* Re: C23 thoughts and opinions4Michael S
9 Jun 24 ii    i i i i i   `* Re: C23 thoughts and opinions3bart
9 Jun 24 ii    i i i i i    `* Re: C23 thoughts and opinions2Michael S
10 Jun 24 ii    i i i i i     `- Re: C23 thoughts and opinions1bart
11 Jun 24 ii    i i i i `- Re: C23 thoughts and opinions1Lawrence D'Oliveiro
10 Jun 24 ii    i i i `- Re: C23 thoughts and opinions1BGB
9 Jun 24 ii    i i `- Re: C23 thoughts and opinions1Lawrence D'Oliveiro
7 Jun 24 ii    i `* Re: C23 thoughts and opinions4BGB
7 Jun 24 ii    i  `* Re: C23 thoughts and opinions3Lawrence D'Oliveiro
7 Jun 24 ii    i   `* Re: C23 thoughts and opinions2BGB
7 Jun 24 ii    i    `- Re: C23 thoughts and opinions1BGB
31 May 24 ii    +* Re: C23 thoughts and opinions19bart
1 Jun 24 ii    i+* Re: C23 thoughts and opinions4jak
1 Jun 24 ii    ii`* Re: C23 thoughts and opinions3bart
1 Jun 24 ii    ii `* Re: C23 thoughts and opinions2jak
2 Jun 24 ii    ii  `- Re: C23 thoughts and opinions1Tim Rentsch
1 Jun 24 ii    i+* Re: C23 thoughts and opinions10bart
1 Jun 24 ii    ii+* Re: C23 thoughts and opinions5Tim Rentsch
1 Jun 24 ii    iii+- Re: C23 thoughts and opinions1Michael S
2 Jun 24 ii    iii`* Re: C23 thoughts and opinions3Tim Rentsch
6 Jun 24 ii    iii `* objcopy -I binary etc... Was: C23 thoughts and opinions2Michael S
6 Jun 24 ii    iii  `- Re: objcopy -I binary etc... Was: C23 thoughts and opinions1Tim Rentsch
1 Jun 24 ii    ii+- Re: C23 thoughts and opinions1David Brown
1 Jun 24 ii    ii+* Re: C23 thoughts and opinions2bart
4 Jun 24 ii    iii`- Re: C23 thoughts and opinions1Lawrence D'Oliveiro
4 Jun 24 ii    ii`- Re: Correct objcopy Usage (was Re: C23 thoughts and opinions)1Lawrence D'Oliveiro
1 Jun 24 ii    i`* Re: C23 thoughts and opinions4Michael S
2 Jun 24 ii    i +* Re: C23 thoughts and opinions2bart
2 Jun 24 ii    i i`- Re: C23 thoughts and opinions1Michael S
6 Jun 24 ii    i `- Re: C23 thoughts and opinions1Michael S
1 Jun 24 ii    `* Re: C23 thoughts and opinions2Michael S
2 Jun 24 ii     `- Re: C23 thoughts and opinions1Tim Rentsch
31 May 24 i`- Re: C23 thoughts and opinions1bart
31 May 24 +- Re: C23 thoughts and opinions1Kaz Kylheku
31 May 24 +- Re: C23 thoughts and opinions1Malcolm McLean
1 Jun 24 `* Re: C23 thoughts and opinions3Malcolm McLean
1 Jun 24  `* Re: C23 thoughts and opinions2bart
1 Jun 24   `- Re: C23 thoughts and opinions1Malcolm McLean

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal