[PATCH] D72272: [Sanitizers] Elf mapping update of FreeBSD offset

Ed Maste via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 4 06:23:45 PST 2020


emaste added inline comments.


================
Comment at: compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.h:27
 # define GET_LINK_MAP_BY_DLOPEN_HANDLE(handle) \
-    ((link_map*)((handle) == nullptr ? nullptr : ((char*)(handle) + 560)))
+    ((link_map*)((handle) == nullptr ? nullptr : ((char*)(handle) + 568)))
 // Get sys/_types.h, because that tells us whether 64-bit inodes are
----------------
dim wrote:
> eugenis wrote:
> > dim wrote:
> > > MaskRay wrote:
> > > > Can you use `offsetof` instead of the magic number? In the description you can add a reference to the commit that causes the change.
> > > Ideally we shouldn't include any system headers here, right?  Otherwise it is not possible to use offsetof, and we should choose the value based on e.g. `__FreeBSD_version`.  @emaste any thoughts?
> > > 
> > If you'd like, you could include a system header in the corresponding .cpp file, store the offset value in a global and use that global in this macro.
> > 
> The relevant header file, rtld.h is not exported, but private to the dynamic linker.  Officially, you can get the linkmap by calling dlinfo(3) with `RTLD_DI_LINKMAP` as the request, and this method has been supported for a very long time now.
> 
> But maybe it is not feasible to call this here?  Are we allow to call the non-intercepted `dlinfo()` at this point?
> 
I tried `printf("%zu\n", offsetof(Obj_Entry, linkmap));` against my development tree and get 560. We're either going to need to indeed use dlinfo() or have an ugly, fragile, and not fully correct set of `__FreeBSD_version` tests.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72272/new/

https://reviews.llvm.org/D72272





More information about the llvm-commits mailing list