Hi! This PR reports a problem on some PCH tests due to -grecord-dwarf-switches, sometimes .debug_str section is emitted in different order with PCH than without. I can't reproduce the issue unless -fno-eliminate-unused-debug-types, but anyway, I hope this patch should cure it. The problem is that without PCH dwarf2out_finish wasn't replacing the producer string with the right one, while with PCH it would be (older one would come from the header file compilation restored from PCH file) and thus the debug_str_hash table contained one extra string (while not referenced and thus not emitted could change the order in which htab_traverse traversed the hash table). With -feliminate-unused-debug-types the hash table is htab_empty cleared afterwards and repopulated, but guess if one is unlucky enough the one extra entry before htab_empty might result in bigger hash table and thus different layout of the hash table.
Fixed by initially setting DW_AT_producer to an empty string and unconditionally fixing it up at dwarf2out_finish time. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2012-11-07 Jakub Jelinek <ja...@redhat.com> PR debug/53145 * dwarf2out.c (gen_compile_unit_die): Don't call gen_producer_string here, instead add "" if producer_string is NULL. (dwarf2out_finish): Call gen_producer_string here, unconditionally decrease refcount of the old indirect string and set val_str to find_AT_string result. --- gcc/dwarf2out.c.jj 2012-11-07 08:42:30.000000000 +0100 +++ gcc/dwarf2out.c 2012-11-07 18:59:38.667571248 +0100 @@ -18867,9 +18867,7 @@ gen_compile_unit_die (const char *filena add_comp_dir_attribute (die); } - if (producer_string == NULL) - producer_string = gen_producer_string (); - add_AT_string (die, DW_AT_producer, producer_string); + add_AT_string (die, DW_AT_producer, producer_string ? producer_string : ""); /* If our producer is LTO try to figure out a common language to use from the global list of translation units. */ @@ -23217,13 +23215,12 @@ dwarf2out_finish (const char *filename) dw_die_ref main_comp_unit_die; /* PCH might result in DW_AT_producer string being restored from the - header compilation, fix it up if needed. */ + header compilation, so always fill it with empty string initially + and overwrite only here. */ dw_attr_ref producer = get_AT (comp_unit_die (), DW_AT_producer); - if (strcmp (AT_string (producer), producer_string) != 0) - { - struct indirect_string_node *node = find_AT_string (producer_string); - producer->dw_attr_val.v.val_str = node; - } + producer_string = gen_producer_string (); + producer->dw_attr_val.v.val_str->refcount--; + producer->dw_attr_val.v.val_str = find_AT_string (producer_string); gen_scheduled_generic_parms_dies (); gen_remaining_tmpl_value_param_die_attribute (); Jakub