This patch adds an msan interceptor for dladdr1 (with support for RTLD_DL_LINKMAP and RTLD_DL_SYMENT) and an accompanying test. It also adds a helper file, msan_dl.cpp, that contains UnpoisonDllAddrInfo (refactored out of the dladdr interceptor) and UnpoisonDllAddr1ExtraInfo.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
compiler-rt/lib/msan/msan_interceptors.cpp | ||
---|---|---|
1551–1567 | what if we move these into a separate cpp file and include headers with them And add most of interceptor body into UnpoisonDllAddr1ExtraInfo() | |
1551–1567 | e.g. msan_dl.cpp | |
compiler-rt/test/msan/dladdr1_test.c | ||
4 | do you need FileCheck here, or asserts is enough? |
compiler-rt/lib/msan/msan_interceptors.cpp | ||
---|---|---|
1551–1567 | same struct dlinfo |
compiler-rt/lib/msan/msan_interceptors.cpp | ||
---|---|---|
1551–1567 | Good idea, I will make those changes and update this CL. | |
compiler-rt/test/msan/dladdr1_test.c | ||
4 | // CHECK: libc.so // CHECK: dladdr1_test are inconvenient to implement as asserts, because they're not exact matches. The output on my machine is: 0x563819032000: '', 0x563819035dc8 0x7ffe4b330000: 'linux-vdso.so.1', 0x7ffe4b3303e0 0x7fb9237d7000: '/lib/x86_64-linux-gnu/libc.so.6', 0x7fb9239a8b60 0x7fb9239d2000: '/lib64/ld-linux-x86-64.so.2', 0x7fb923a03e20 0x7fb9239cb000: '/tmp/dl-so.so', 0x7fb9239cee20 but I expect subtle differences on build bots and other machines that aren't precisely the same 64-bit Linux. |
compiler-rt/test/msan/dladdr1_test.c | ||
---|---|---|
4 | Oops, that last line of the output should be 0x7f96e35b6000: '/usr/local/google/home/thurston/llvm-projectD/build/projects/compiler-rt/test/msan/lld-X86_64/Output/dladdr1_test.c.tmp-so.so', 0x7f96e35b86a8 (the previous output was from my working copy in /tmp) |
compiler-rt/lib/msan/msan_dl.h | ||
---|---|---|
13 | that's not what I suggested suggestion is to not define these structs but: |
compiler-rt/lib/msan/msan_dl.h | ||
---|---|---|
13 | Ah, I see. Let me fix that. |
"#include <dlfcn.h> and friends in a cpp file and export function like UnpoisonDllAddr1ExtraInfo"
compiler-rt/lib/msan/msan_dl.cpp | ||
---|---|---|
22–28 |
compiler-rt/lib/msan/msan_interceptors.cpp | ||
---|---|---|
1551–1567 | If I #include dlfcn.h to get the definition of struct Dl_info, it will also drag in the declaration of dladdr/dladdr1/dlerror, conflicting with the interceptors. I suspect that's why msan_interceptors.cpp had defined their own struct dlinfo. |
compiler-rt/lib/msan/msan_interceptors.cpp | ||
---|---|---|
1551–1567 | you will include dlfcn.h only into msan_dl.cpp |
compiler-rt/lib/msan/msan_dl.cpp | ||
---|---|---|
40 | can map be nullptr? we may crash on l_prev then |
compiler-rt/lib/msan/msan_interceptors.cpp | ||
---|---|---|
1551–1567 | I ended up also having to replace Dl_info* with void*, in everywhere except msan_dl.cpp. |
compiler-rt/lib/msan/msan_dl.cpp | ||
---|---|---|
2 | still no header? //===-- msan_interceptors.cpp ---------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// | |
compiler-rt/lib/msan/msan_dl.h | ||
2 | also //===-- msan_interceptors.cpp ---------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// |
compiler-rt/lib/msan/msan_dl.cpp | ||
---|---|---|
2 | Sorry, I misinterpreted "add standard file headers" as "add #include <x.h>". I'll fix. |
compiler-rt/lib/msan/msan_dl.cpp | ||
---|---|---|
2–5 |
compiler-rt/lib/msan/msan_dl.cpp | ||
---|---|---|
43–52 |
Fix 'cast from 'void ' to 'const Elf64_Sym ' must have all intermediate pointers const qualified to be safe [-Werror,-Wcast-qual]'
This change broke the build of msan on FreeBSD. dladdr1 seems to be a glibc-ism and is not present in FreeBSD or musl. All this functionality needs to be gated by a CMake check.
@brooks Thanks for the heads up, and apologies for the inconvenience. To fix the build, I've reverted my patch (https://reviews.llvm.org/rG015dabd7672f936cdb5bdcad20fe80b17f05c9ca) and will gate it appropriately before I reland it.
also