blob: d8e4a3ec1a85c490460b4fee6e2836e9998570f3 [file] [log] [blame]
Elliott Hughes838dbac2023-08-22 14:07:48 -07001/*
2 * Copyright (C) 2023 The Android Open Source Project
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in
12 * the documentation and/or other materials provided with the
13 * distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
29#include "linker_auxv.h"
30
31#include <elf.h>
32#include <stdio.h>
33#include <sys/auxv.h>
34#include <unistd.h>
35
36#include <async_safe/log.h>
37
38static const char* auxv_name(int at) {
39 switch (at) {
40 case AT_NULL: return "AT_NULL";
41 case AT_IGNORE: return "AT_IGNORE";
42 case AT_EXECFD: return "AT_EXECFD";
43 case AT_PHDR: return "AT_PHDR";
44 case AT_PHENT: return "AT_PHENT";
45 case AT_PHNUM: return "AT_PHNUM";
46 case AT_PAGESZ: return "AT_PAGESZ";
47 case AT_BASE: return "AT_BASE";
48 case AT_FLAGS: return "AT_FLAGS";
49 case AT_ENTRY: return "AT_ENTRY";
50 case AT_NOTELF: return "AT_NOTELF";
51 case AT_UID: return "AT_UID";
52 case AT_EUID: return "AT_EUID";
53 case AT_GID: return "AT_GID";
54 case AT_EGID: return "AT_EGID";
55 case AT_PLATFORM: return "AT_PLATFORM";
56 case AT_HWCAP: return "AT_HWCAP";
57 case AT_CLKTCK: return "AT_CLKTCK";
58 case AT_SECURE: return "AT_SECURE";
59 case AT_BASE_PLATFORM: return "AT_BASE_PLATFORM";
60 case AT_RANDOM: return "AT_RANDOM";
61 case AT_HWCAP2: return "AT_HWCAP2";
62 case AT_RSEQ_FEATURE_SIZE: return "AT_RSEQ_FEATURE_SIZE";
63 case AT_RSEQ_ALIGN: return "AT_RSEQ_ALIGN";
64 case AT_EXECFN: return "AT_EXECFN";
65 case AT_SYSINFO_EHDR: return "AT_SYSINFO_EHDR";
66#if defined(AT_MINSIGSTKSZ)
67 case AT_MINSIGSTKSZ: return "AT_MINSIGSTKSZ";
68#endif
69#if defined(AT_SYSINFO)
70 case AT_SYSINFO: return "AT_SYSINFO";
71#endif
72#if defined(AT_L1I_CACHESIZE)
73 case AT_L1I_CACHESIZE: return "AT_L1I_CACHESIZE";
74#endif
75#if defined(AT_L1I_CACHEGEOMETRY)
76 case AT_L1I_CACHEGEOMETRY: return "AT_L1I_CACHEGEOMETRY";
77#endif
78#if defined(AT_L1D_CACHESIZE)
79 case AT_L1D_CACHESIZE: return "AT_L1D_CACHESIZE";
80#endif
81#if defined(AT_L1D_CACHEGEOMETRY)
82 case AT_L1D_CACHEGEOMETRY: return "AT_L1D_CACHEGEOMETRY";
83#endif
84#if defined(AT_L2_CACHESIZE)
85 case AT_L2_CACHESIZE: return "AT_L2_CACHESIZE";
86#endif
87#if defined(AT_L2_CACHEGEOMETRY)
88 case AT_L2_CACHEGEOMETRY: return "AT_L2_CACHEGEOMETRY";
89#endif
90 }
91 static char name[32];
92 snprintf(name, sizeof(name), "AT_??? (%d)", at);
93 return name;
94}
95
96void ld_show_auxv(ElfW(auxv_t)* auxv) {
97 for (ElfW(auxv_t)* v = auxv; v->a_type != AT_NULL; ++v) {
98 const char* name = auxv_name(v->a_type);
99 long value = v->a_un.a_val;
100 switch (v->a_type) {
101 case AT_SYSINFO_EHDR:
102 case AT_PHDR:
103 case AT_BASE:
104 case AT_ENTRY:
105 case AT_RANDOM:
106 async_safe_format_fd(STDOUT_FILENO, "%-20s %#lx\n", name, value);
107 break;
108 case AT_FLAGS:
109 case AT_HWCAP:
110 case AT_HWCAP2:
111 async_safe_format_fd(STDOUT_FILENO, "%-20s %#lb\n", name, value);
112 break;
113 case AT_EXECFN:
114 case AT_PLATFORM:
115 async_safe_format_fd(STDOUT_FILENO, "%-20s \"%s\"\n", name, reinterpret_cast<char*>(value));
116 break;
117 default:
118 async_safe_format_fd(STDOUT_FILENO, "%-20s %ld\n", name, value);
119 break;
120 }
121 }
122}