This is an archive of the discontinued LLVM Phabricator instance.

[XCOFF] Write source language ID and CPU version ID into C_FILE symbol.
ClosedPublic

Authored by Esme on Jul 19 2023, 2:00 AM.

Details

Summary

The source language ID and CPU version ID are required by debuggers.
AIX's system assembler determines the source language ID based on the source file's name suffix, and the behavior in this patch is consistent with it.

Diff Detail

Event Timeline

Esme created this revision.Jul 19 2023, 2:00 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 19 2023, 2:00 AM
Esme requested review of this revision.Jul 19 2023, 2:00 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 19 2023, 2:00 AM
shchenz added inline comments.
llvm/lib/MC/XCOFFObjectWriter.cpp
1116

This is not unreliable, for example you can compile files with many kinds of suffix or even without suffix as a c++ file if you specify -x c++. However seems we don't have accurate info in IR to identify the language ID if no -g. So I think it is OK here to have same handling with system assembler.

System assembler treats following suffix as C++ file:

.C, .cc, .ii, .cpp, .cxx, .c++
.ccm, .iim, .cppm, .cxxm, .c++m
.CC, .CPP, .CXX, .C++

Copied from @stephenpeckham

1123

Why set the default to 0XC?(assembly file? we won't use integrated-assembler to compile assembly files). Maybe we can default to C++ like traceback table does, and by doing this, we also have consistent language ID in the symbol table and the trace back table.

shchenz added inline comments.Jul 19 2023, 6:25 AM
llvm/lib/MC/XCOFFObjectWriter.cpp
1121

Please also handle the FORTRAN suffixs

llvm/lib/MC/XCOFFObjectWriter.cpp
1107–1108

You could use FileName instead of F.first.

By the way, the system assembler generates a C_FILE symbol with auxiliary symbol table entries, allowing the compiler version and timestamp to be specified. (That might need a separate patch.)

llvm/lib/MC/XCOFFObjectWriter.cpp
1120

Shouldn't this be "endswith" instead of "ends_with_insensitive"? Otherwise, .C looks like TB_C. Maybe you should check for .c first, then default to TB_CPLUSPLUS. (If you want checks for other languages, such as Fortran, you could add them.).

Esme added inline comments.Jul 19 2023, 9:57 PM
llvm/lib/MC/XCOFFObjectWriter.cpp
1121

Thanks!
However I'm not quite sure what suffixes the system's assembler would judge as FORTRAN?

Esme updated this revision to Diff 542381.Jul 20 2023, 2:11 AM
Esme marked 6 inline comments as done.

Addressed comments. Thanks! @stephenpeckham @shchenz

I don't see a testcase for source_filename ending with ".c".

@Esme, iiuc, the integrated-as mode was made the default on AIX during the LLVM 17 development cycle and, without this, there is a regression in debugging Clang-compiled programs with AIX dbx?
If so, I believe this should be considered for the LLVM 17 release branch (i.e., backport if this does not land before the release split).

Esme added a comment.Jul 20 2023, 9:44 PM

I don't see a testcase for source_filename ending with ".c".

Please see llvm/test/CodeGen/PowerPC/aix-filename-c.ll. Does it meet your expectation?

Esme added a comment.Jul 20 2023, 9:57 PM

@Esme, iiuc, the integrated-as mode was made the default on AIX during the LLVM 17 development cycle and, without this, there is a regression in debugging Clang-compiled programs with AIX dbx?
If so, I believe this should be considered for the LLVM 17 release branch (i.e., backport if this does not land before the release split).

Yes, dbx requires the correct source language ID to locate symbols.
Thank you for reminding!

Please see llvm/test/CodeGen/PowerPC/aix-filename-c.ll. Does it meet your expectation?

Yes, sorry. I missed seeing that test earlier.

shchenz accepted this revision as: shchenz.Jul 21 2023, 7:21 PM

LGTM. Thanks for fixing this.

This revision is now accepted and ready to land.Jul 21 2023, 7:21 PM
This revision was landed with ongoing or failed builds.Jul 23 2023, 9:35 PM
This revision was automatically updated to reflect the committed changes.