This is in part a gcc bug and a gdb bug. GCC doesn't add DW_AT_comp_dir to type units, which normally doesn't matter. For completeness sake, attached is a testcase where it matters. [which isn't to say this is an important bug to fix]
Created attachment 8259 [details] testcase and fix (on the gdb side)