This is an archive of the discontinued LLVM Phabricator instance.

Work around non-existence of ElfW(type) macro on FreeBSD
ClosedPublic

Authored by dim on Aug 3 2021, 12:36 PM.

Details

Summary

Fixes PR51331. On FreeBSD, the elf headers don't (yet) provide the
ElfW(type) macro. However, there is a similar set of macros in the
<sys/elf-generic.h> header, of which __ElfN(type) exactly matches the
indended purpose.

Diff Detail

Event Timeline

dim created this revision.Aug 3 2021, 12:36 PM
dim requested review of this revision.Aug 3 2021, 12:36 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 3 2021, 12:36 PM
Herald added a subscriber: Restricted Project. · View Herald Transcript
gulfem accepted this revision.Aug 3 2021, 1:00 PM
This revision is now accepted and ready to land.Aug 3 2021, 1:00 PM
MaskRay added a subscriber: MaskRay.Aug 3 2021, 1:17 PM
MaskRay added inline comments.
compiler-rt/lib/profile/InstrProfilingPlatformLinux.c
21

If FreeBSD will have the macro, add a comment so that this chunk can be removed in the future.

dim added inline comments.Aug 3 2021, 1:35 PM
compiler-rt/lib/profile/InstrProfilingPlatformLinux.c
21

Newer versions might have it, but older released versions won't. That's what the !defined(ElfW) is for. But you're right that a comment is appropriate.

dim updated this revision to Diff 363875.Aug 3 2021, 1:54 PM

Add comment about the FreeBSD ElfW(type) workaround.

dim updated this revision to Diff 363886.Aug 3 2021, 3:04 PM

Squash commits so buildkite doesn't choke.

This revision was automatically updated to reflect the committed changes.
MaskRay added inline comments.Aug 4 2021, 11:28 AM
compiler-rt/lib/profile/InstrProfilingPlatformLinux.c
23

(I expected an exact version, instead of a vague "If this is added to all supported FreeBSD versions in the future")

Without the comment, a reader may remember to clean up this as well.

dim added inline comments.Aug 4 2021, 11:43 AM
compiler-rt/lib/profile/InstrProfilingPlatformLinux.c
23

Well, predictions are hard, especially about the future. :)

That said, if we add this macro to FreeBSD 14.0-CURRENT, it can be merged back to the existing stable branches, which are currently:

  • 11.4-STABLE (but this expires in 2 months so there isn't going be a 11.5-RELEASE)
  • 12.3-STABLE, which will likely result in 12.3-RELEASE at some point, but the date is not yet determined
  • 13.1-STABLE, which will likely result in 13.1-RELEASE at some point, but the date is not yet determined

This type of addition is usually not added to existing releases, which typically only provide security fixes, and bug fixes that affect a large number of users.