Skip to content

Commit 691b12a

Browse files
authored
[compiler-rt] simplifying ::ReExec for freebsd. (#79711)
taking the getauxval route since elf_aux_info is available since FBSD 12.
1 parent bfbd0da commit 691b12a

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_getauxval.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,20 @@ static inline decltype(AuxInfo::a_v) getauxval(decltype(AuxInfo::a_type) type) {
5555
return 0;
5656
}
5757

58+
#elif SANITIZER_FREEBSD
59+
# include <sys/auxv.h>
60+
61+
# define SANITIZER_USE_GETAUXVAL 1
62+
# define AT_EXECFN AT_EXECPATH
63+
64+
static inline unsigned long getauxval(unsigned long type) {
65+
unsigned long buf = 0ul;
66+
67+
if (elf_aux_info(static_cast<int>(type), &buf, sizeof(buf)))
68+
return 0ul;
69+
return buf;
70+
}
71+
5872
#endif
5973

6074
#endif // SANITIZER_GETAUXVAL_H

compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -934,14 +934,7 @@ u64 MonotonicNanoTime() {
934934
void ReExec() {
935935
const char *pathname = "/proc/self/exe";
936936

937-
# if SANITIZER_FREEBSD
938-
for (const auto *aux = __elf_aux_vector; aux->a_type != AT_NULL; aux++) {
939-
if (aux->a_type == AT_EXECPATH) {
940-
pathname = static_cast<const char *>(aux->a_un.a_ptr);
941-
break;
942-
}
943-
}
944-
# elif SANITIZER_NETBSD
937+
# if SANITIZER_NETBSD
945938
static const int name[] = {
946939
CTL_KERN,
947940
KERN_PROC_ARGS,

0 commit comments

Comments
 (0)