This is an archive of the discontinued LLVM Phabricator instance.

Undef FS and CS macros for Android x86_64
AbandonedPublic

Authored by chh on Aug 15 2022, 3:39 PM.

Details

Reviewers
srhines
Summary

Android bionic x86_64 .h file defines the FS and CS macros.
Some lldb files have included the bionic .h files
before these files where FS and CS are used
as parameters or variables.

Diff Detail

Event Timeline

chh created this revision.Aug 15 2022, 3:39 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 15 2022, 3:39 PM
chh requested review of this revision.Aug 15 2022, 3:39 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 15 2022, 3:39 PM
chh updated this revision to Diff 452850.Aug 15 2022, 4:52 PM
pirama added a subscriber: pirama.Aug 19 2022, 2:47 PM

Adding the #undefs at the point of conflicting variable makes the fixes hard to read/maintain. These macros are defined through the #include <sys/ptrace.h> in lldb/source/Plugins/Process/Linux/Procfs.h. It may be cleaner to #undef these macros after the #include in Procfs.h with a comment. We should also wrap the fix with a #ifdef ANDROID.

chh added a comment.Aug 19 2022, 3:12 PM

If #undef is only inserted into Procfs.h or conditioned for ANDROID, that will only fix one include path or use case.
These .h files won't compile for other include paths or with any other system files that define FS or CS.
An alternative is not to use FS or CS in these .h files, but #undef before use seems less intrusive.

An alternative is not to use FS or CS in these .h files, but #undef before use seems less intrusive.

Fixing it like this is confusing though. CS and FS are used in several other header files in llvm and clang. And this fits perfectly into the coding style used in LLVM. With this fix, it's unclear why we need to undef FS|CS in LLVM some headers and not others. The reason is subtle in that it's needed only for those headers that are included in lldb _after_ Android's ptrace.h is included. Fixing this break closer to the point of origin of the discrepancy makes it easier to understand.

These .h files won't compile for other include paths or with any other system files that define FS or CS.

AFAICT, the include in Procfs.h is the only instance of this error. Building lldb-server passes with adding a #undef there. If other include paths arise in the future, we can revisit and extend this fix while still keeping it self-contained.

chh abandoned this revision.Sep 14 2022, 1:08 PM