This is an archive of the discontinued LLVM Phabricator instance.

Re: Work around non-existence of ElfW(type) macro on FreeBSD
AbandonedPublic

Authored by gAlfonso-bit on Aug 4 2021, 11:39 AM.

Details

Reviewers
dim
MaskRay
Summary

FreeBSD contributor here! Although this code works, this is not the first time this macro comes up, and the way it is defined is a little different. Because of this, the workaround that is used is

#if !defined(ElfW)
#define ElfW(type) Elf_##type
#endif

And that is consistent across the entire codebase

Diff Detail

Event Timeline

gAlfonso-bit created this revision.Aug 4 2021, 11:39 AM
gAlfonso-bit requested review of this revision.Aug 4 2021, 11:39 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 4 2021, 11:39 AM
Herald added a subscriber: Restricted Project. · View Herald Transcript

All other changes were done by running clang-tidy and clang-format on the file

dim added a comment.Aug 4 2021, 1:07 PM

Hmm in compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp it's even defined without any context or comment:

#if !defined(ElfW)
#define ElfW(type) Elf_##type
#endif

libunwind/src/AddressSpace.hpp also has it, but with more explanatory text, and additional typedefs:

#if defined(_LIBUNWIND_USE_DL_ITERATE_PHDR)

// The ElfW() macro for pointer-size independent ELF header traversal is not
// provided by <link.h> on some systems (e.g., FreeBSD). On these systems the
// data structures are just called Elf_XXX. Define ElfW() locally.
#if !defined(ElfW)
  #define ElfW(type) Elf_##type
#endif
#if !defined(Elf_Half)
  typedef ElfW(Half) Elf_Half;
#endif
#if !defined(Elf_Phdr)
  typedef ElfW(Phdr) Elf_Phdr;
#endif
#if !defined(Elf_Addr)
  typedef ElfW(Addr) Elf_Addr;
#endif

While I think it's a good stop-gap to define these things locally, at least to get release candidates built, it looks like this is maybe something that we should define in some globally usable LLVM header? @MaskRay do you know if there's a good central ELF-related header that could serve this purpose?

gAlfonso-bit updated this revision to Diff 364596.EditedAug 5 2021, 1:13 PM

Added context to patch

MaskRay added a comment.EditedAug 6 2021, 8:00 PM

lib/profile/InstrProfilingPort.h. But I think it may be early to move it or generalize the macro for now. NetBSD seems to have ElfW.

MaskRay requested changes to this revision.Aug 6 2021, 8:00 PM
This revision now requires changes to proceed.Aug 6 2021, 8:00 PM

lib/profile/InstrProfilingPort.h. But I think it may be early to move it or generalize the macro for now. NetBSD seems to have ElfW.

What do we do then? Because this seems wrong

Any updates? Should we try to make the macros consistent or should I just abandon this?

gAlfonso-bit abandoned this revision.Nov 12 2021, 9:17 AM

Will revisit this one day.