Hi! Here is an incremental fix on top of the https://gcc.gnu.org/pipermail/gcc-patches/2025-April/680256.html patch. As I said, there were various FAILs in make check-cobol when using the cross compiler from 32-bit host to x86_64-linux. This patch fixes most of them, except for Running /home/jakub/src/gcc/gcc/testsuite/cobol.dg/dg.exp ... FAIL: cobol.dg/group1/declarative_1.cob -O0 execution test FAIL: cobol.dg/group1/declarative_1.cob -O1 execution test FAIL: cobol.dg/group1/declarative_1.cob -O2 execution test FAIL: cobol.dg/group1/declarative_1.cob -O3 -fomit-frame-pointer -funroll-loops -fpeel-loops -ftracer -finline-functions execution test FAIL: cobol.dg/group1/declarative_1.cob -O3 -g execution test FAIL: cobol.dg/group1/declarative_1.cob -Os execution test
=== cobol Summary === # of expected passes 3123 # of unexpected failures 6 # of expected failures 6 (which has some analysis but not a fix yet). This patch fixes various cases where host size of various types (void *, int, size_t, unsigned char) is used in place where size of those types in bytes on the target should be used instead. At least the size of void * and size_t actually differns between ilp32 hosts and lp64 targets, int could be different in theory as well but we actually don't support 16-bit ints on the host side and only support lp64 targets right now for cobol, and finally sizeof(unsigned char) is always 1, so there is no point to multiply by that and it is still wrong to use host sizeof for the target decisions. Bootstrapped/regtested on x86_64-linux and tested with following on x86_64-linux, ok for trunk? PATH=~/hbin:/usr/local/x86_64-redhat-linux-gnu/bin:$PATH i386 ../configure --target x86_64-redhat-linux-gnu -enable-languages=cobol --disable-lto --enable-checking=yes,rtl,extra --disable-bootstrap --disable-libsanitizer --disable-libgomp --disable-multilib PATH=~/hbin:/usr/local/x86_64-redhat-linux-gnu/bin:$PATH i386 make -j32 cd gcc; make check-cobol where ls ~/hbin as g++ gcc gdc ld for i in ~/hbin/*; do echo ===$i===; cat $i; done ===/home/jakub/hbin/as=== #!/bin/sh exec /usr/bin/as --32 "$@" ===/home/jakub/hbin/g++=== #!/bin/sh exec /usr/bin/g++ -m32 "$@" ===/home/jakub/hbin/gcc=== #!/bin/sh exec /usr/bin/gcc -m32 "$@" ===/home/jakub/hbin/gdc=== #!/bin/sh exec /usr/bin/gdc -m32 "$@" ===/home/jakub/hbin/ld=== #!/bin/sh case "$*" in --version) cat <<\EOF GNU ld version 2.20.52.0.1-10.fc17 20100131 Copyright 2012 Free Software Foundation, Inc. This program is free software; you may redistribute it under the terms of the GNU General Public License version 3 or (at your option) a later version. This program has absolutely no warranty. EOF exit 0;; esac exec /usr/bin/ld -m elf_i386 -L /usr/lib/ "$@" ls -l /usr/local/x86_64-redhat-linux-gnu/ total 32 drwxr-xr-x. 2 jakub jakub 4096 Apr 6 11:54 bin lrwxrwxrwx. 1 jakub jakub 12 Apr 6 11:33 include -> /usr/include drwxr-xr-x. 2 jakub jakub 24576 Apr 6 12:49 lib lrwxrwxrwx. 1 jakub jakub 10 Apr 6 11:33 lib64 -> /usr/lib64 ls -l /usr/local/x86_64-redhat-linux-gnu/bin total 0 lrwxrwxrwx. 1 jakub jakub 11 Apr 6 11:54 ar -> /usr/bin/ar lrwxrwxrwx. 1 jakub jakub 11 Apr 6 11:44 as -> /usr/bin/as lrwxrwxrwx. 1 jakub jakub 16 Apr 6 11:23 c++filt -> /usr/bin/c++filt lrwxrwxrwx. 1 jakub jakub 11 Apr 6 11:23 ld -> /usr/bin/ld lrwxrwxrwx. 1 jakub jakub 15 Apr 6 11:23 ld.bfd -> /usr/bin/ld.bfd lrwxrwxrwx. 1 jakub jakub 11 Apr 6 11:23 nm -> /usr/bin/nm lrwxrwxrwx. 1 jakub jakub 16 Apr 6 11:23 objcopy -> /usr/bin/objcopy lrwxrwxrwx. 1 jakub jakub 16 Apr 6 11:23 objdump -> /usr/bin/objdump lrwxrwxrwx. 1 jakub jakub 15 Apr 6 11:23 ranlib -> /usr/bin/ranlib lrwxrwxrwx. 1 jakub jakub 16 Apr 6 11:23 readelf -> /usr/bin/readelf lrwxrwxrwx. 1 jakub jakub 13 Apr 6 11:23 size -> /usr/bin/size lrwxrwxrwx. 1 jakub jakub 16 Apr 6 11:23 strings -> /usr/bin/strings lrwxrwxrwx. 1 jakub jakub 14 Apr 6 11:23 strip -> /usr/bin/strip lrwxrwxrwx. 1 jakub jakub 11 Apr 6 11:54 x86_64-redhat-linux-gnu-ar -> /usr/bin/ar lrwxrwxrwx. 1 jakub jakub 11 Apr 6 11:44 x86_64-redhat-linux-gnu-as -> /usr/bin/as lrwxrwxrwx. 1 jakub jakub 16 Apr 6 11:23 x86_64-redhat-linux-gnu-c++filt -> /usr/bin/c++filt lrwxrwxrwx. 1 jakub jakub 11 Apr 6 11:23 x86_64-redhat-linux-gnu-ld -> /usr/bin/ld lrwxrwxrwx. 1 jakub jakub 15 Apr 6 11:23 x86_64-redhat-linux-gnu-ld.bfd -> /usr/bin/ld.bfd lrwxrwxrwx. 1 jakub jakub 11 Apr 6 11:23 x86_64-redhat-linux-gnu-nm -> /usr/bin/nm lrwxrwxrwx. 1 jakub jakub 16 Apr 6 11:23 x86_64-redhat-linux-gnu-objcopy -> /usr/bin/objcopy lrwxrwxrwx. 1 jakub jakub 16 Apr 6 11:23 x86_64-redhat-linux-gnu-objdump -> /usr/bin/objdump lrwxrwxrwx. 1 jakub jakub 15 Apr 6 11:23 x86_64-redhat-linux-gnu-ranlib -> /usr/bin/ranlib lrwxrwxrwx. 1 jakub jakub 16 Apr 6 11:23 x86_64-redhat-linux-gnu-readelf -> /usr/bin/readelf lrwxrwxrwx. 1 jakub jakub 13 Apr 6 11:23 x86_64-redhat-linux-gnu-size -> /usr/bin/size lrwxrwxrwx. 1 jakub jakub 16 Apr 6 11:23 x86_64-redhat-linux-gnu-strings -> /usr/bin/strings lrwxrwxrwx. 1 jakub jakub 14 Apr 6 11:23 x86_64-redhat-linux-gnu-strip -> /usr/bin/strip ls -l /usr/local/x86_64-redhat-linux-gnu/lib/*.o -rw-r--r--. 1 jakub jakub 13456 May 11 2022 /usr/local/x86_64-redhat-linux-gnu/lib/crt1.o -rw-r--r--. 1 jakub jakub 1728 May 11 2022 /usr/local/x86_64-redhat-linux-gnu/lib/crti.o -rw-r--r--. 1 jakub jakub 1464 May 11 2022 /usr/local/x86_64-redhat-linux-gnu/lib/crtn.o -rw-r--r--. 1 jakub jakub 17632 May 11 2022 /usr/local/x86_64-redhat-linux-gnu/lib/gcrt1.o -rw-r--r--. 1 jakub jakub 13864 May 11 2022 /usr/local/x86_64-redhat-linux-gnu/lib/grcrt1.o -rw-r--r--. 1 jakub jakub 5624 May 11 2022 /usr/local/x86_64-redhat-linux-gnu/lib/Mcrt1.o -rw-r--r--. 1 jakub jakub 9840 May 11 2022 /usr/local/x86_64-redhat-linux-gnu/lib/rcrt1.o -rw-r--r--. 1 jakub jakub 9840 May 11 2022 /usr/local/x86_64-redhat-linux-gnu/lib/Scrt1.o plus in that directory ln -sf /usr/lib64/*.so /usr/local/x86_64-redhat-linux-gnu/lib/ 2025-04-08 Jakub Jelinek <ja...@redhat.com> PR cobol/119364 * genapi.cc (function_handle_from_name): Use sizeof_pointer. (parser_file_add): Use int_size_in_bytes(VOID_P) and int_size_in_bytes(int). (inspect_tally): Use int_size_in_bytes(VOID_P). (inspect_replacing): Likewise. (gg_array_of_field_pointers): Likewise. (gg_array_of_file_pointers): Likewise. (parser_set_pointers): Use sizeof_pointer. * cobol1.cc (create_our_type_nodes_init): Use int_size_in_bytes(SIZE_T) and int_size_in_bytes(VOID_P). * gengen.cc (gg_array_of_size_t): Use int_size_in_bytes(SIZE_T). (gg_array_of_bytes): Just use N, don't multiply it by sizeof(unsigned char). * parse.y: Include tree.h. Use int_size_in_bytes(ptr_type_node). --- gcc/cobol/genapi.cc.jj 2025-04-05 22:10:21.699956654 +0200 +++ gcc/cobol/genapi.cc 2025-04-07 19:42:47.527507356 +0200 @@ -790,13 +790,13 @@ function_handle_from_name(cbl_refer_t &n { gg_memcpy(gg_get_address_of(function_handle), member(name.field->var_decl_node, "data"), - build_int_cst_type(SIZE_T, sizeof(void *))); + sizeof_pointer); } else { gg_memcpy(gg_get_address_of(function_handle), qualified_data_source(name), - build_int_cst_type(SIZE_T, sizeof(void *))); + sizeof_pointer); } return function_handle; } @@ -8931,8 +8931,8 @@ parser_file_add(struct cbl_file_t *file) gg_assign(array_of_keys, gg_cast(build_pointer_type(cblc_field_p_type_node), gg_malloc(build_int_cst_type(SIZE_T, - (number_of_key_fields+1) - *sizeof(void *))))); + (number_of_key_fields+1) + *int_size_in_bytes(VOID_P))))); strcpy(achName, "_"); strcat(achName, file->name); @@ -8943,8 +8943,8 @@ parser_file_add(struct cbl_file_t *file) gg_assign(key_numbers, gg_cast(build_pointer_type(INT), gg_malloc(build_int_cst_type(SIZE_T, - (number_of_key_fields+1) - *sizeof(int))))); + (number_of_key_fields+1) + *int_size_in_bytes(INT))))); strcpy(achName, "_"); strcat(achName, file->name); @@ -8956,7 +8956,7 @@ parser_file_add(struct cbl_file_t *file) gg_cast(build_pointer_type(INT), gg_malloc(build_int_cst_type(SIZE_T, (number_of_key_fields+1) - *sizeof(int))))); + *int_size_in_bytes(INT))))); size_t index = 0; for( size_t i=0; i<file->nkey; i++ ) @@ -9700,7 +9700,9 @@ inspect_tally(bool backward, gg_assign(int_size, build_int_cst_type(INT, n_integers)); gg_assign(integers, gg_cast(SIZE_T_P, - gg_realloc(integers, n_integers * sizeof(void *)))); + gg_realloc(integers, + n_integers + * int_size_in_bytes(VOID_P)))); } ELSE { @@ -9851,7 +9853,9 @@ inspect_replacing(int backward, gg_assign(int_size, build_int_cst_type(INT, n_integers)); gg_assign(integers, gg_cast(SIZE_T_P, - gg_realloc(integers, n_integers * sizeof(void *)))); + gg_realloc(integers, + n_integers + * int_size_in_bytes(VOID_P)))); } ELSE { @@ -11089,7 +11093,9 @@ gg_array_of_field_pointers( size_t N, cbl_field_t **fields ) { tree retval = gg_define_variable(build_pointer_type(cblc_field_p_type_node)); - gg_assign(retval, gg_cast(build_pointer_type(cblc_field_p_type_node), gg_malloc( build_int_cst_type(SIZE_T, N * sizeof(void *))))); + gg_assign(retval, gg_cast(build_pointer_type(cblc_field_p_type_node), + gg_malloc(build_int_cst_type(SIZE_T, + N * int_size_in_bytes(VOID_P))))); for(size_t i=0; i<N; i++) { gg_assign(gg_array_value(retval, i), gg_get_address_of(fields[i]->var_decl_node)); @@ -11581,7 +11587,8 @@ gg_array_of_file_pointers( size_t N, { tree retval = gg_define_variable(build_pointer_type(cblc_file_p_type_node)); gg_assign(retval, gg_cast( build_pointer_type(cblc_file_p_type_node), - gg_malloc( build_int_cst_type(SIZE_T, N * sizeof(void *))))); + gg_malloc( build_int_cst_type(SIZE_T, + N * int_size_in_bytes(VOID_P))))); for(size_t i=0; i<N; i++) { gg_assign(gg_array_value(retval, i), gg_get_address_of(files[i]->var_decl_node)); @@ -12868,7 +12875,7 @@ parser_set_pointers( size_t ntgt, cbl_re COBOL_FUNCTION_RETURN_TYPE); gg_memcpy(qualified_data_dest(tgts[i]), gg_get_address_of(function_handle), - build_int_cst_type(SIZE_T, sizeof(void *))); + sizeof_pointer); } else { --- gcc/cobol/cobol1.cc.jj 2025-04-05 22:09:20.016801774 +0200 +++ gcc/cobol/cobol1.cc 2025-04-07 19:31:10.235221294 +0200 @@ -166,8 +166,8 @@ create_our_type_nodes_init() long_double_ten_node = build_real_from_int_cst( LONGDOUBLE, build_int_cst_type(INT,10)); - sizeof_size_t = build_int_cst_type(SIZE_T, sizeof(size_t)); - sizeof_pointer = build_int_cst_type(SIZE_T, sizeof(void *)); + sizeof_size_t = build_int_cst_type(SIZE_T, int_size_in_bytes(SIZE_T)); + sizeof_pointer = build_int_cst_type(SIZE_T, int_size_in_bytes(VOID_P)); bool_true_node = build2(EQ_EXPR, integer_type_node, --- gcc/cobol/gengen.cc.jj 2025-04-05 22:10:21.688956805 +0200 +++ gcc/cobol/gengen.cc 2025-04-07 19:40:35.410347873 +0200 @@ -3356,7 +3356,8 @@ tree gg_array_of_size_t( size_t N, size_t *values) { tree retval = gg_define_variable(build_pointer_type(SIZE_T)); - gg_assign(retval, gg_cast(build_pointer_type(SIZE_T), gg_malloc( build_int_cst_type(SIZE_T, N * sizeof(size_t))))); + tree sz = build_int_cst_type(SIZE_T, N * int_size_in_bytes(SIZE_T)); + gg_assign(retval, gg_cast(build_pointer_type(SIZE_T), gg_malloc(sz))); for(size_t i=0; i<N; i++) { gg_assign(gg_array_value(retval, i), build_int_cst_type(SIZE_T, values[i])); @@ -3368,7 +3369,7 @@ tree gg_array_of_bytes( size_t N, unsigned char *values) { tree retval = gg_define_variable(UCHAR_P); - gg_assign(retval, gg_cast(UCHAR_P, gg_malloc( build_int_cst_type(SIZE_T, N * sizeof(unsigned char))))); + gg_assign(retval, gg_cast(UCHAR_P, gg_malloc( build_int_cst_type(SIZE_T, N)))); for(size_t i=0; i<N; i++) { gg_assign(gg_array_value(retval, i), build_int_cst_type(UCHAR, values[i])); --- gcc/cobol/parse.y.jj 2025-04-05 22:10:21.694956723 +0200 +++ gcc/cobol/parse.y 2025-04-07 20:01:32.722832141 +0200 @@ -34,6 +34,7 @@ #include "coretypes.h" #include "../../libgcobol/io.h" #include "../../libgcobol/ec.h" + #include "tree.h" #pragma GCC diagnostic ignored "-Wmissing-field-initializers" @@ -3826,7 +3827,8 @@ data_clauses: data_clause if( yydebug ) { yywarn("expanding %s size from %u bytes to %zu " "because it redefines %s with USAGE POINTER", - field->name, field->size(), sizeof(void*), + field->name, field->size(), + (size_t)int_size_in_bytes(ptr_type_node), redefined->name); } field->embiggen(); @@ -4286,7 +4288,7 @@ usage_clause1: usage COMPUTATIONAL[comp if( gcobol_feature_embiggen() && redefined && is_numeric(redefined->type) && redefined->size() == 4) { // For now, we allow POINTER to expand a 32-bit item to 64 bits. - field->data.capacity = sizeof(void *); + field->data.capacity = int_size_in_bytes(ptr_type_node); dbgmsg("%s: expanding #" HOST_SIZE_T_PRINT_UNSIGNED " %s capacity %u => %u", __func__, (fmt_size_t)field_index(redefined), redefined->name, Jakub