https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82005

--- Comment #6 from Richard Biener <rguenth at gcc dot gnu.org> ---
To recap the situation we have sth like

earlyDebug.o

section .debug_info:
sym1:
  CU1
...
  CU2 at coff1


lateDebug.o

section .debug_info:
...
 DW_TAG_imported_unit
   DW_AT_import $sym1 - .debug_info + coff1


I suppose we could somehow rely on .debug_info being relocated to 0.  Changing
the assembler that way works (but we're missing the provider of the early debug
so I can't double-check the final dwarf).

I suppose we'd need a new dw2_asm_output primitive for this (offset
within zero-relocated section, sym + offset) plus the associated target
macro.  Or put that knowledge (section is relocated to zero) into
darwin_asm_output_dwarf_offset somehow.  Like with

Index: config/darwin.c
===================================================================
--- config/darwin.c     (revision 251449)
+++ config/darwin.c     (working copy)
@@ -2859,7 +2859,8 @@ darwin_asm_output_dwarf_delta (FILE *fil
                               const char *lab1, const char *lab2,
                               HOST_WIDE_INT offset)
 {
-  int islocaldiff = (lab1[0] == '*' && lab1[1] == 'L'
+  int islocaldiff = (lab2
+                    && lab1[0] == '*' && lab1[1] == 'L'
                     && lab2[0] == '*' && lab2[1] == 'L');
   const char *directive = (size == 8 ? ".quad" : ".long");

@@ -2869,8 +2870,11 @@ darwin_asm_output_dwarf_delta (FILE *fil
     fprintf (file, "\t%s\t", directive);

   assemble_name_raw (file, lab1);
-  fprintf (file, "-");
-  assemble_name_raw (file, lab2);
+  if (lab2)
+    {
+      fprintf (file, "-");
+      assemble_name_raw (file, lab2);
+    }
   if (offset != 0)
     fprintf (file, "+" HOST_WIDE_INT_PRINT_DEC, offset);
   if (islocaldiff)
@@ -2905,7 +2909,9 @@ darwin_asm_output_dwarf_offset (FILE *fi
       extra = 4;
     }
   snprintf (sname, 64, "*Lsection%.*s%.*s", namelen, name, extra, lto_add);
-  darwin_asm_output_dwarf_delta (file, size, lab, sname, offset);
+  darwin_asm_output_dwarf_delta (file, size, lab,
+                                strncmp (name, "__debug_info", namelen)
+                                ? sname : NULL, offset);
 }

 /* Called from the within the TARGET_ASM_FILE_START for each target.  */


that seems to work with and without -flto up to the extent that UNDEFs
(the early debug is not extracted and thus not linked) seem to be
resolved to zero by the link editor.

Reply via email to