aboutsummaryrefslogtreecommitdiff
path: root/libjava
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2025-05-02 19:09:34 +0200
committerJakub Jelinek <jakub@gcc.gnu.org>2025-05-02 19:11:53 +0200
commit4704b94fc76b51e79e6fcf63344f70da4d89d75c (patch)
tree6da1acf7f7c12b975c18d698850c70c3240b88d9 /libjava
parent1789c57dc97ea2f9819ef89e28bf17208b6208e7 (diff)
downloadgcc-4704b94fc76b51e79e6fcf63344f70da4d89d75c.zip
gcc-4704b94fc76b51e79e6fcf63344f70da4d89d75c.tar.gz
gcc-4704b94fc76b51e79e6fcf63344f70da4d89d75c.tar.bz2
cobol, v2: Fix up cobol cross-compilation from 32-bit arches [PR119364]
Right now it is not possible to even build cross-compilers from 32-bit architectures to e.g. x86_64-linux or aarch64-linux, even from little-endian ones. The following patch attempts to fix that. There were various issues seen e.g. trying to build i686-linux -> x86_64-linux cross-compiler (so still 64-bit libgcobol, but the compiler is 32-bit). 1) warning about >> 32 shift of size_t, on 32-bit arches size_t is 32-bit and so the shift is UB; fixed by doing (new_size>>16)>>16 so that it ors in >> 32 when new_size is 64-bit and 0 when it is 32-bit 2) enum cbl_field_attr_t was using size_t as underlying type, but has various bitmasks which require full 64-bit type; changed this to uint64_t underlying type and using unsigned long long in the structure; various routines which operate with those attributes had to be changed also to work with uint64_t instead of size_t 3) on i686-linux, config.h can #define _FILE_OFFSET_BITS 64 or similar macros; as documented, those macros have to be defined before including first C library header, but some sources included cobol-system.h which includes config.h only after various other headers; this resulted in link failures, as ino_t was sometimes unsigned long and sometines unsigned long long, depending on whether config.h was included first or not, and e.g. cobol_filename uses ino_t argument 4) lots of places used %ld or %lx *printf format specifers with size_t arguments; that works only if size_t is unsigned long, but not when it is unsigned int or unsigned long long or some other type; now while ISO C99 has %zd or %zx to print size_t and C++14 includes C99 (or C11?), while for the C++ headers the C++ compilers typically have full control over it and so support everything in C++14 (e.g. libstdc++ in GCC 5.1+ or libc++ if not too old), for C library we are dependent on the system C library (note, on the host for the compiler side). And not all hosts support C99 in their C libraries; so instead of just changing it to %zd or %zx, I'm changing it to what we use elsewhere in GCC, HOST_SIZE_T_PRINT_{DEC,UNSIGNED,HEX_PURE} or GCC_PRISZ macros in the *printf family format string and casts of the size_t arguments to fmt_size_t. Note, if not using the C library *printf family (e.g. in dbgmsg, sprintf, snprintf, fprintf, etc.) but the GCC diagnostic code (e.g. err_msg, error, warning, yywarn, ...), then %zd/%zu is supported and on the other side HOST_SIZE_T_PRINT_{DEC,UNSIGNED,HEX_PURE} etc. macros shouldn't be used (for two reasons, because it is unnecessary when %zd/%zu is guaranteed to be supported there because GCC has control over that and more importantly because it breaks translations, both extraction of the to be translated strings and we don't want to have different messages, once with %lld, once with %ld, once with just %d or %I64d depending on host, translators couldn't translate it all). 5) see above, there were already tons of %zd/%zu or %3zu etc. format specifers in *printf format strings, this patch changes those too 6) I've noticed dbgmsg wasn't declared with printf attribute, which resulted in bugs where format specifiers didn't match actually passed types of arguments 2025-05-02 Jakub Jelinek <jakub@redhat.com> PR cobol/119364 libgcobol/ * valconv.cc (__gg__realloc_if_necessary): Use (new_size>>16)>>16; instead of new_size>>32; to avoid warnings on 32-bit hosts. * common-defs.h (enum cbl_field_attr_t): Use uint64_t as underlying type rather than size_t. * gcobolio.h (cblc_field_t): Change attr member type from size_t to unsigned long long. gcc/cobol/ * util.cc (is_numeric_edited): Use HOST_SIZE_T_PRINT_UNSIGNED instead of "%zu" and cast corresponding argument to fmt_size_t. (normalize_picture): Use GCC_PRISZ instead of "z" and pass address of fmt_size_t var to sscanf and copy afterwards. (cbl_refer_t::str): Use HOST_SIZE_T_PRINT_UNSIGNED instead of "%zu" or GCC_PRISZ instead of "z" and cast corresponding argument to fmt_size_t. (struct move_corresponding_field): Likewise. (valid_move): Likewise. (ambiguous_reference): Likewise. (parent_names): Likewise. (find_corresponding::find_corresponding): Likewise. (corresponding_fields): Likewise. (unique_stack::push): Likewise. (cobol_filename): Likewise. * lexio.cc: Include config.h first. (recognize_replacements): Use HOST_SIZE_T_PRINT_UNSIGNED instead of "%zu" or GCC_PRISZ instead of "z" and cast corresponding argument to fmt_size_t. (check_source_format_directive): Likewise. (parse_replacing_pair): Use size_t(0) instead of 0UL in span_t construction. (parse_replace_pairs): Use HOST_SIZE_T_PRINT_UNSIGNED instead of "%zu" or GCC_PRISZ instead of "z" or HOST_SIZE_T_PRINT_DEC instead of "%zd" and cast corresponding argument to fmt_size_t. (parse_copy_directive): Likewise. (parse_replace_last_off): Likewise. (parse_replace_text): Likewise. (bytespan_t::append): Likewise. (cdftext::map_file): Likewise. (cdftext::process_file): Likewise. * symfind.cc (dump_symbol_map2): Likewise. (dump_symbol_map_value): Likewise. (build_symbol_map): Likewise. (is_name::dump_key): Likewise. (symbol_match2): Likewise. (symbol_find): Likewise. (symbol_find_of): Likewise. * cdf.y: Likewise. * symbols.cc: Include config.h first. (cbl_field_t::set_attr): Return uint64_t rather than size_t and replace size_t(attr) with uint64_t(attr). (cbl_field_t::clear_attr): Likewise. (symbol_field_capacity): Use HOST_SIZE_T_PRINT_UNSIGNED instead of "%zu" or GCC_PRISZ instead of "z" or HOST_SIZE_T_PRINT_DEC instead of "%zd" and cast corresponding argument to fmt_size_t. (symbol_find_odo_debug): Likewise. (symbols_dump): Likewise. (calculate_capacity): Likewise. (field_str): Likewise. (symbols_update): Likewise. (symbol_field_forward): Likewise. (numeric_group_attrs): Return uint64_t rather than size_t and change inherit variable to from size_t to uint64_t. (new_literal_add): Use HOST_SIZE_T_PRINT_UNSIGNED instead of "%zu" or GCC_PRISZ instead of "z" or HOST_SIZE_T_PRINT_DEC instead of "%zd" and cast corresponding argument to fmt_size_t. (temporaries_t::dump): Likewise. (cbl_label_t::str): Likewise. (symbol_label_add): Likewise. (symbol_program_add): Likewise. (symbol_forward_names): Likewise. (symbol_forward_to): Likewise. (cbl_file_key_t::deforward): Likewise. (cbl_file_key_t::str): Likewise. * gengen.cc (show_type): Use PRId64 instead of "ld". (gg_unique_in_function): Use HOST_SIZE_T_PRINT_DEC instead of %ld and cast corresponding argument to fmt_size_t. * scan.l: Add %top section with #include "config.h". * genmath.cc (parser_add): Use HOST_SIZE_T_PRINT_DEC instead of %ld and cast corresponding argument to fmt_size_t. (parser_subtract): Likewise. * parse.y: Include "config.h" before <fstream>. Use HOST_SIZE_T_PRINT_UNSIGNED instead of "%zu" and cast corresponding argument to fmt_size_t. Change type of sign_attrs, group_sign and type_implies from size_t to uint64_t. (perform_t::ec_labels_t::new_label): Use HOST_SIZE_T_PRINT_UNSIGNED instead of "%zu" or GCC_PRISZ instead of "z" or HOST_SIZE_T_PRINT_DEC instead of "%zd" and cast corresponding argument to fmt_size_t. (stringify_src_t::dump): Likewise. (lang_check_failed): Likewise. (numstr2i): Use GCC_PRISZ instead of "z" and pass address of temporary with fmt_size_t type to sscanf and then copy it over. (initialize_statement): Use HOST_SIZE_T_PRINT_UNSIGNED instead of "%zu" or GCC_PRISZ instead of "z" or HOST_SIZE_T_PRINT_DEC instead of "%zd" and cast corresponding argument to fmt_size_t. (dump_inspect_oper): Likewise. (new_literal): Likewise. (literal_subscripts_valid): Likewise. (eval_subject_t::label): Likewise. * genapi.cc (level_88_helper): Likewise. (parser_call_targets_dump): Likewise. (combined_name): Use HOST_SIZE_T_PRINT_DEC instead of "%ld" and cast corresponding argument to fmt_size_t. (section_label): Likewise. (paragraph_label): Likewise. (leave_procedure): Likewise. (parser_perform): Likewise. (parser_perform_times): Likewise. (internal_perform_through): Likewise. (internal_perform_through_times): Likewise. (parser_enter_program): Likewise. (parser_init_list_size): Likewise. (parser_init_list): Likewise. (psa_FldLiteralN): Likewise. (psa_FldBlob): Likewise. (parser_assign): Likewise. (parser_free): Pass p->field->name to dbgmsg. (parser_division): Use HOST_SIZE_T_PRINT_DEC instead of "%ld" and cast corresponding argument to fmt_size_t. (perform_outofline_before_until): Likewise. (perform_outofline_after_until): Likewise. (perform_outofline_testafter_varying): Likewise. (perform_outofline_before_varying): Likewise. (perform_inline_testbefore_varying): Likewise. (parser_inspect): Change n_operations parameter type from unsigned long to size_t. (parser_intrinsic_callv): Use HOST_SIZE_T_PRINT_DEC instead of "%zd" and cast corresponding argument to fmt_size_t. (parser_bitop): Use HOST_SIZE_T_PRINT_HEX_PURE instead of "%lx" and cast corresponding argument to fmt_size_t. (parser_bitwise_op): Likewise. (parser_program_hierarchy): Use HOST_SIZE_T_PRINT_DEC instead of "%ld" and cast corresponding argument to fmt_size_t. (parser_set_handled): Use HOST_SIZE_T_PRINT_HEX_PURE instead of "%lx" and cast corresponding argument to fmt_size_t. (parser_set_numeric): Use HOST_SIZE_T_PRINT_DEC instead of "%ld" and cast corresponding argument to fmt_size_t. (psa_new_var_decl): Use HOST_SIZE_T_PRINT_DEC instead of "%ld" and cast corresponding argument to fmt_size_t. (parser_symbol_add): Use HOST_SIZE_T_PRINT_DEC instead of "%zd" or HOST_SIZE_T_PRINT_HEX_PURE instead of "%lx" and cast corresponding argument to fmt_size_t. * cdf-copy.cc: Include "config.h" first. * scan_ante.h (trim_location): Use HOST_SIZE_T_PRINT_UNSIGNED instead of "%zu" or "%d" and cast corresponding argument to fmt_size_t. * structs.cc (create_cblc_field_t): Use ULONGLONG instead of SIZE for "attr". * cbldiag.h (dbgmsg): Add ATTRIBUTE_PRINTF_1. * gcobolspec.cc (lang_specific_driver): Use HOST_SIZE_T_PRINT_DEC instead of "%ld" and cast corresponding argument to fmt_size_t. * parse_ante.h (literal_of): Use HOST_SIZE_T_PRINT_UNSIGNED instead of "%zu" or GCC_PRISZ instead of "z" or HOST_SIZE_T_PRINT_DEC instead of "%zd" and cast corresponding argument to fmt_size_t. (evaluate_elem_t::dump): Likewise. (arith_t::another_pair): Likewise. (current_t::end_program): Likewise. (file_add): Likewise. (implicit_paragraph): Likewise. (implicit_section): Likewise. (data_division_ready): Use HOST_SIZE_T_PRINT_DEC instead of "%d" and cast corresponding argument to fmt_size_t. * symbols.h (struct cbl_field_t): Change attr member type from size_t to uint64_t. (cbl_field_t::set_attr): Change return type from size_t to uint64_t. (cbl_field_t::clear_attr): Likewise. (function_descr_t::init): Use HOST_SIZE_T_PRINT_UNSIGNED instead of "%zu" or GCC_PRISZ instead of "z" or HOST_SIZE_T_PRINT_DEC instead of "%zd" and cast corresponding argument to fmt_size_t. (cbl_perform_tgt_t::dump): Likewise. (numeric_group_attrs): Change return type from size_t to uint64_t.
Diffstat (limited to 'libjava')
0 files changed, 0 insertions, 0 deletions