This is an archive of the discontinued LLVM Phabricator instance.

[Driver] Let -fno-integrated-as -gdwarf-5 use -fdwarf-directory-asm
ClosedPublic

Authored by MaskRay on Jul 12 2021, 12:30 PM.

Details

Summary

While GNU as only allows the directory form of the .file directive for DWARF v5,
the integrated assembler prefers the directory form on all DWARF versions
(-fdwarf-directory-asm).

We currently set CC1 -fno-dwarf-directory-asm for -fno-integrated-as -gdwarf-5
which may cause the directory entry 0 and the filename entry 0 to be incorrect
(see D105662 and the example below). This patch makes -fno-integrated-as -gdwarf-5 use
-fdwarf-directory-asm as well.

cd /tmp/c

before
% clang -g -gdwarf-5 -fno-integrated-as e/a.c -S -o - | grep '\.file.*0'
        .file   0 "/tmp/c/e/a.c" md5 0x97e31cee64b4e58a4af8787512d735b6
% clang -g -gdwarf-5 -fno-integrated-as e/a.c -c
% llvm-dwarfdump a.o | grep include_directories
include_directories[  0] = "/tmp/c/e"

after
% clang -g -gdwarf-5 -fno-integrated-as e/a.c -S -o - | grep '\.file.*0'
        .file   0 "/tmp/c" "e/a.c" md5 0x97e31cee64b4e58a4af8787512d735b6
% clang -g -gdwarf-5 -fno-integrated-as e/a.c -c
% llvm-dwarfdump a.o | grep include_directories
include_directories[  0] = "/tmp/c"

Diff Detail

Event Timeline

MaskRay requested review of this revision.Jul 12 2021, 12:30 PM
MaskRay created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptJul 12 2021, 12:30 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
MaskRay edited the summary of this revision. (Show Details)Jul 12 2021, 12:32 PM
MaskRay edited the summary of this revision. (Show Details)Jul 12 2021, 12:35 PM

Not sure I quite follow - is this an alternative to/replacement for D105662? Is the intent to revert D105662 after this (D105835) (& some corresponding change to llc?) lands?

Not sure I quite follow - is this an alternative to/replacement for D105662? Is the intent to revert D105662 after this (D105835) (& some corresponding change to llc?) lands?

It is an alternative to D105662.

This fixes the root cause: UseDwarfDirectory should be true with -fno-integrated-as -gdwarf-5.

I tested my reproducer and it also fixes it, thanks. Should it be an error to specify -fno-dwarf-directory-asm together with -gdwarf-5, since that produces incorrect results?

MaskRay added a comment.EditedJul 12 2021, 3:02 PM

I tested my reproducer and it also fixes it, thanks. Should it be an error to specify -fno-dwarf-directory-asm together with -gdwarf-5, since that produces incorrect results?

I thought about this, but did not add the code because I think the option -fno-dwarf-directory-asm is so obscure that probably nobody will use...
Not sure why it became a driver option... An internal CC1 option probably suffices.

osandov accepted this revision.Jul 12 2021, 3:11 PM

That's fair enough. I don't know if I'm qualified to review this, but this I think this is a better solution than my fix.

This revision is now accepted and ready to land.Jul 12 2021, 3:11 PM
dblaikie accepted this revision.Jul 12 2021, 3:33 PM

Sure, sounds OK. Please make the corresponding change to llc and revert the other patch after this one & the llc one are done.

MaskRay edited the summary of this revision. (Show Details)Jul 12 2021, 3:40 PM
MaskRay edited the summary of this revision. (Show Details)
This revision was landed with ongoing or failed builds.Jul 12 2021, 3:46 PM
This revision was automatically updated to reflect the committed changes.