xref: /aosp_15_r20/art/dex2oat/dex2oat_options.cc (revision 795d594fd825385562da6b089ea9b2033f3abf5a)
1*795d594fSAndroid Build Coastguard Worker /*
2*795d594fSAndroid Build Coastguard Worker  * Copyright (C) 2017 The Android Open Source Project
3*795d594fSAndroid Build Coastguard Worker  *
4*795d594fSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*795d594fSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*795d594fSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*795d594fSAndroid Build Coastguard Worker  *
8*795d594fSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*795d594fSAndroid Build Coastguard Worker  *
10*795d594fSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*795d594fSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*795d594fSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*795d594fSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*795d594fSAndroid Build Coastguard Worker  * limitations under the License.
15*795d594fSAndroid Build Coastguard Worker  */
16*795d594fSAndroid Build Coastguard Worker 
17*795d594fSAndroid Build Coastguard Worker #include "dex2oat_options.h"
18*795d594fSAndroid Build Coastguard Worker 
19*795d594fSAndroid Build Coastguard Worker #include <memory>
20*795d594fSAndroid Build Coastguard Worker 
21*795d594fSAndroid Build Coastguard Worker #include "cmdline_parser.h"
22*795d594fSAndroid Build Coastguard Worker #include "driver/compiler_options_map-inl.h"
23*795d594fSAndroid Build Coastguard Worker 
24*795d594fSAndroid Build Coastguard Worker namespace art {
25*795d594fSAndroid Build Coastguard Worker 
26*795d594fSAndroid Build Coastguard Worker template<>
27*795d594fSAndroid Build Coastguard Worker struct CmdlineType<InstructionSet> : CmdlineTypeParser<InstructionSet> {
Parseart::CmdlineType28*795d594fSAndroid Build Coastguard Worker   Result Parse(const std::string& option) {
29*795d594fSAndroid Build Coastguard Worker     InstructionSet set = GetInstructionSetFromString(option.c_str());
30*795d594fSAndroid Build Coastguard Worker     if (set == InstructionSet::kNone) {
31*795d594fSAndroid Build Coastguard Worker       return Result::Failure(std::string("Not a valid instruction set: '") + option + "'");
32*795d594fSAndroid Build Coastguard Worker     }
33*795d594fSAndroid Build Coastguard Worker     return Result::Success(set);
34*795d594fSAndroid Build Coastguard Worker   }
35*795d594fSAndroid Build Coastguard Worker 
Nameart::CmdlineType36*795d594fSAndroid Build Coastguard Worker   static const char* Name() { return "InstructionSet"; }
DescribeTypeart::CmdlineType37*795d594fSAndroid Build Coastguard Worker   static const char* DescribeType() { return "arm|arm64|riscv64|x86|x86_64|none"; }
38*795d594fSAndroid Build Coastguard Worker };
39*795d594fSAndroid Build Coastguard Worker 
40*795d594fSAndroid Build Coastguard Worker #define COMPILER_OPTIONS_MAP_TYPE Dex2oatArgumentMap
41*795d594fSAndroid Build Coastguard Worker #define COMPILER_OPTIONS_MAP_KEY_TYPE Dex2oatArgumentMapKey
42*795d594fSAndroid Build Coastguard Worker #include "driver/compiler_options_map-storage.h"
43*795d594fSAndroid Build Coastguard Worker 
44*795d594fSAndroid Build Coastguard Worker // Specify storage for the Dex2oatOptions keys.
45*795d594fSAndroid Build Coastguard Worker 
46*795d594fSAndroid Build Coastguard Worker #define DEX2OAT_OPTIONS_KEY(Type, Name, ...) \
47*795d594fSAndroid Build Coastguard Worker   const Dex2oatArgumentMap::Key<Type> Dex2oatArgumentMap::Name {__VA_ARGS__};
48*795d594fSAndroid Build Coastguard Worker #include "dex2oat_options.def"
49*795d594fSAndroid Build Coastguard Worker 
50*795d594fSAndroid Build Coastguard Worker #pragma GCC diagnostic push
51*795d594fSAndroid Build Coastguard Worker #pragma GCC diagnostic ignored "-Wframe-larger-than="
52*795d594fSAndroid Build Coastguard Worker 
53*795d594fSAndroid Build Coastguard Worker using M = Dex2oatArgumentMap;
54*795d594fSAndroid Build Coastguard Worker using Parser = CmdlineParser<Dex2oatArgumentMap, Dex2oatArgumentMap::Key>;
55*795d594fSAndroid Build Coastguard Worker using Builder = Parser::Builder;
56*795d594fSAndroid Build Coastguard Worker 
AddInputMappings(Builder & builder)57*795d594fSAndroid Build Coastguard Worker static void AddInputMappings(Builder& builder) {
58*795d594fSAndroid Build Coastguard Worker   // clang-format off
59*795d594fSAndroid Build Coastguard Worker   builder.
60*795d594fSAndroid Build Coastguard Worker       Define("--dex-file=_")
61*795d594fSAndroid Build Coastguard Worker           .WithType<std::vector<std::string>>().AppendValues()
62*795d594fSAndroid Build Coastguard Worker           .WithHelp("Specifies a .dex, .jar, or .apk file to compile.\n"
63*795d594fSAndroid Build Coastguard Worker                     "Eg: --dex-file=/system/framework/core.jar")
64*795d594fSAndroid Build Coastguard Worker           .WithMetavar("<dex-file>")
65*795d594fSAndroid Build Coastguard Worker           .IntoKey(M::DexFiles)
66*795d594fSAndroid Build Coastguard Worker       .Define("--dex-location=_")
67*795d594fSAndroid Build Coastguard Worker           .WithType<std::vector<std::string>>().AppendValues()
68*795d594fSAndroid Build Coastguard Worker           .WithMetavar("<dex-location>")
69*795d594fSAndroid Build Coastguard Worker           .WithHelp("specifies an alternative dex location to encode in the oat file for the\n"
70*795d594fSAndroid Build Coastguard Worker                     "corresponding --dex-file argument. The first --dex-location corresponds to\n"
71*795d594fSAndroid Build Coastguard Worker                     "the first --dex-file, the second to the second and so on.\n"
72*795d594fSAndroid Build Coastguard Worker                     "Eg: --dex-file=/home/build/out/system/framework/core.jar\n"
73*795d594fSAndroid Build Coastguard Worker                     "    --dex-location=/system/framework/core.jar")
74*795d594fSAndroid Build Coastguard Worker           .IntoKey(M::DexLocations)
75*795d594fSAndroid Build Coastguard Worker       .Define("--dex-fd=_")
76*795d594fSAndroid Build Coastguard Worker           .WithType<std::vector<int>>().AppendValues()
77*795d594fSAndroid Build Coastguard Worker           .WithHelp("Specifies a file descriptor of a dex file. It can be specified for multiple\n"
78*795d594fSAndroid Build Coastguard Worker                     "times, but the number must match the number of --dex-file. Eg: --dex-fd=5")
79*795d594fSAndroid Build Coastguard Worker           .IntoKey(M::DexFds)
80*795d594fSAndroid Build Coastguard Worker       .Define("--zip-fd=_")
81*795d594fSAndroid Build Coastguard Worker           .WithType<int>()
82*795d594fSAndroid Build Coastguard Worker           .WithHelp("specifies a file descriptor of a zip file containing a classes.dex file to\n"
83*795d594fSAndroid Build Coastguard Worker                     "compile. Eg: --zip-fd=5")
84*795d594fSAndroid Build Coastguard Worker           .IntoKey(M::ZipFd)
85*795d594fSAndroid Build Coastguard Worker       .Define("--zip-location=_")
86*795d594fSAndroid Build Coastguard Worker           .WithType<std::string>()
87*795d594fSAndroid Build Coastguard Worker           .WithHelp("Specifies a symbolic name for the file corresponding to the FD given by\n"
88*795d594fSAndroid Build Coastguard Worker                     "--zip-fd.")
89*795d594fSAndroid Build Coastguard Worker           .IntoKey(M::ZipLocation)
90*795d594fSAndroid Build Coastguard Worker       .Define("--boot-image=_")
91*795d594fSAndroid Build Coastguard Worker           .WithType<std::string>()
92*795d594fSAndroid Build Coastguard Worker           .WithHelp("provide the image file for the boot class path.\n"
93*795d594fSAndroid Build Coastguard Worker                     "Do not include the arch as part of the name, it is added automatically.\n"
94*795d594fSAndroid Build Coastguard Worker                     "Example: --boot-image=/system/framework/boot.art\n"
95*795d594fSAndroid Build Coastguard Worker                     "         (specifies /system/framework/<arch>/boot.art as the image file)\n"
96*795d594fSAndroid Build Coastguard Worker                     "Example: --boot-image=boot.art:boot-framework.art\n"
97*795d594fSAndroid Build Coastguard Worker                     "         (specifies <bcp-path1>/<arch>/boot.art as the image file and\n"
98*795d594fSAndroid Build Coastguard Worker                     "         <bcp-path2>/<arch>/boot-framework.art as the image extension file\n"
99*795d594fSAndroid Build Coastguard Worker                     "         with paths taken from corresponding boot class path components)\n"
100*795d594fSAndroid Build Coastguard Worker                     "Example: --boot-image=/apex/com.android.art/boot.art:/system/framework/*:*\n"
101*795d594fSAndroid Build Coastguard Worker                     "         (specifies /apex/com.android.art/<arch>/boot.art as the image\n"
102*795d594fSAndroid Build Coastguard Worker                     "         file and search for extensions in /framework/system and boot\n"
103*795d594fSAndroid Build Coastguard Worker                     "         class path components' paths)\n"
104*795d594fSAndroid Build Coastguard Worker                     "Default: $ANDROID_ROOT/system/framework/boot.art")
105*795d594fSAndroid Build Coastguard Worker           .IntoKey(M::BootImage);
106*795d594fSAndroid Build Coastguard Worker   // clang-format on
107*795d594fSAndroid Build Coastguard Worker }
108*795d594fSAndroid Build Coastguard Worker 
AddGeneratedArtifactMappings(Builder & builder)109*795d594fSAndroid Build Coastguard Worker static void AddGeneratedArtifactMappings(Builder& builder) {
110*795d594fSAndroid Build Coastguard Worker   // clang-format off
111*795d594fSAndroid Build Coastguard Worker   builder.
112*795d594fSAndroid Build Coastguard Worker       Define("--input-vdex-fd=_")
113*795d594fSAndroid Build Coastguard Worker           .WithType<int>()
114*795d594fSAndroid Build Coastguard Worker           .WithHelp("specifies the vdex input source via a file descriptor.")
115*795d594fSAndroid Build Coastguard Worker           .IntoKey(M::InputVdexFd)
116*795d594fSAndroid Build Coastguard Worker       .Define("--input-vdex=_")
117*795d594fSAndroid Build Coastguard Worker           .WithType<std::string>()
118*795d594fSAndroid Build Coastguard Worker           .WithHelp("specifies the vdex input source via a filename.")
119*795d594fSAndroid Build Coastguard Worker           .IntoKey(M::InputVdex)
120*795d594fSAndroid Build Coastguard Worker       .Define("--output-vdex-fd=_")
121*795d594fSAndroid Build Coastguard Worker           .WithHelp("specifies the vdex output destination via a file descriptor.")
122*795d594fSAndroid Build Coastguard Worker           .WithType<int>()
123*795d594fSAndroid Build Coastguard Worker           .IntoKey(M::OutputVdexFd)
124*795d594fSAndroid Build Coastguard Worker       .Define("--output-vdex=_")
125*795d594fSAndroid Build Coastguard Worker           .WithType<std::string>()
126*795d594fSAndroid Build Coastguard Worker           .WithHelp("specifies the vdex output destination via a filename.")
127*795d594fSAndroid Build Coastguard Worker           .IntoKey(M::OutputVdex)
128*795d594fSAndroid Build Coastguard Worker       .Define("--dm-fd=_")
129*795d594fSAndroid Build Coastguard Worker           .WithType<int>()
130*795d594fSAndroid Build Coastguard Worker           .WithHelp("specifies the dm output destination via a file descriptor.")
131*795d594fSAndroid Build Coastguard Worker           .IntoKey(M::DmFd)
132*795d594fSAndroid Build Coastguard Worker       .Define("--dm-file=_")
133*795d594fSAndroid Build Coastguard Worker           .WithType<std::string>()
134*795d594fSAndroid Build Coastguard Worker           .WithHelp("specifies the dm output destination via a filename.")
135*795d594fSAndroid Build Coastguard Worker           .IntoKey(M::DmFile)
136*795d594fSAndroid Build Coastguard Worker       .Define("--oat-file=_")
137*795d594fSAndroid Build Coastguard Worker           .WithType<std::string>()
138*795d594fSAndroid Build Coastguard Worker           .WithHelp(" Specifies an oat output destination via a filename.\n"
139*795d594fSAndroid Build Coastguard Worker                     "Eg: --oat-file=/system/framework/boot.oat")
140*795d594fSAndroid Build Coastguard Worker           .IntoKey(M::OatFile)
141*795d594fSAndroid Build Coastguard Worker       .Define("--oat-symbols=_")
142*795d594fSAndroid Build Coastguard Worker           .WithType<std::string>()
143*795d594fSAndroid Build Coastguard Worker           .WithHelp("Specifies a symbolized oat output destination.\n"
144*795d594fSAndroid Build Coastguard Worker                     "Eg: --oat-symbols=symbols/system/framework/boot.oat")
145*795d594fSAndroid Build Coastguard Worker           .IntoKey(M::OatSymbols)
146*795d594fSAndroid Build Coastguard Worker       .Define("--strip")
147*795d594fSAndroid Build Coastguard Worker           .WithHelp("remove all debugging sections at the end (but keep mini-debug-info).\n"
148*795d594fSAndroid Build Coastguard Worker                     "This is equivalent to the \"strip\" command as build post-processing step.\n"
149*795d594fSAndroid Build Coastguard Worker                     "It is intended to be used with --oat-symbols and it happens after it.\n"
150*795d594fSAndroid Build Coastguard Worker                     "Eg: --oat-symbols=/symbols/system/framework/boot.oat")
151*795d594fSAndroid Build Coastguard Worker           .IntoKey(M::Strip)
152*795d594fSAndroid Build Coastguard Worker       .Define("--oat-fd=_")
153*795d594fSAndroid Build Coastguard Worker           .WithType<int>()
154*795d594fSAndroid Build Coastguard Worker           .WithHelp("Specifies the oat output destination via a file descriptor. Eg: --oat-fd=5")
155*795d594fSAndroid Build Coastguard Worker           .IntoKey(M::OatFd)
156*795d594fSAndroid Build Coastguard Worker       .Define("--oat-location=_")
157*795d594fSAndroid Build Coastguard Worker           .WithType<std::string>()
158*795d594fSAndroid Build Coastguard Worker           .WithHelp("specifies a symbolic name for the file corresponding to the file descriptor\n"
159*795d594fSAndroid Build Coastguard Worker                     "specified by --oat-fd.\n"
160*795d594fSAndroid Build Coastguard Worker                     "Eg: --oat-location=/data/dalvik-cache/system@[email protected]")
161*795d594fSAndroid Build Coastguard Worker           .IntoKey(M::OatLocation);
162*795d594fSAndroid Build Coastguard Worker   // clang-format on
163*795d594fSAndroid Build Coastguard Worker }
164*795d594fSAndroid Build Coastguard Worker 
AddImageMappings(Builder & builder)165*795d594fSAndroid Build Coastguard Worker static void AddImageMappings(Builder& builder) {
166*795d594fSAndroid Build Coastguard Worker   // clang-format off
167*795d594fSAndroid Build Coastguard Worker   builder.
168*795d594fSAndroid Build Coastguard Worker       Define("--image=_")
169*795d594fSAndroid Build Coastguard Worker           .WithType<std::string>()
170*795d594fSAndroid Build Coastguard Worker           .WithHelp("specifies an output image filename. Eg: --image=/system/framework/boot.art")
171*795d594fSAndroid Build Coastguard Worker           .IntoKey(M::ImageFilename)
172*795d594fSAndroid Build Coastguard Worker       .Define("--image-fd=_")
173*795d594fSAndroid Build Coastguard Worker           .WithType<int>()
174*795d594fSAndroid Build Coastguard Worker           .WithHelp("specifies an output image file descriptor. Cannot be used with --image.\n"
175*795d594fSAndroid Build Coastguard Worker                     "Eg: --image-fd=7")
176*795d594fSAndroid Build Coastguard Worker           .IntoKey(M::ImageFd)
177*795d594fSAndroid Build Coastguard Worker       .Define("--base=_")
178*795d594fSAndroid Build Coastguard Worker           .WithType<std::string>()
179*795d594fSAndroid Build Coastguard Worker           .WithHelp("Specifies the base address when creating a boot image. Eg: --base=0x50000000")
180*795d594fSAndroid Build Coastguard Worker           .WithMetavar("{hex address}")
181*795d594fSAndroid Build Coastguard Worker           .IntoKey(M::Base)
182*795d594fSAndroid Build Coastguard Worker       .Define("--app-image-file=_")
183*795d594fSAndroid Build Coastguard Worker           .WithType<std::string>()
184*795d594fSAndroid Build Coastguard Worker           .WithHelp("Specify a file name for app image. Only used if a profile is passed in.")
185*795d594fSAndroid Build Coastguard Worker           .IntoKey(M::AppImageFile)
186*795d594fSAndroid Build Coastguard Worker       .Define("--app-image-fd=_")
187*795d594fSAndroid Build Coastguard Worker           .WithType<int>()
188*795d594fSAndroid Build Coastguard Worker           .WithHelp("Specify a file descriptor for app image. Only used if a profile is passed in.")
189*795d594fSAndroid Build Coastguard Worker           .IntoKey(M::AppImageFileFd)
190*795d594fSAndroid Build Coastguard Worker       .Define({"--multi-image", "--single-image"})
191*795d594fSAndroid Build Coastguard Worker           .WithValues({true, false})
192*795d594fSAndroid Build Coastguard Worker           .WithHelp("Specifies if separate oat and image files should be generated for each dex\n"
193*795d594fSAndroid Build Coastguard Worker                     "file. --multi-image is default for boot image and --single-image for app\n"
194*795d594fSAndroid Build Coastguard Worker                     "images.")
195*795d594fSAndroid Build Coastguard Worker           .IntoKey(M::MultiImage)
196*795d594fSAndroid Build Coastguard Worker       .Define("--dirty-image-objects=_")
197*795d594fSAndroid Build Coastguard Worker           .WithType<std::vector<std::string>>().AppendValues()
198*795d594fSAndroid Build Coastguard Worker           .WithHelp("list of known dirty objects in the image. The image writer will group them"
199*795d594fSAndroid Build Coastguard Worker                     " together")
200*795d594fSAndroid Build Coastguard Worker           .IntoKey(M::DirtyImageObjects)
201*795d594fSAndroid Build Coastguard Worker       .Define("--dirty-image-objects-fd=_")
202*795d594fSAndroid Build Coastguard Worker           .WithType<std::vector<int>>().AppendValues()
203*795d594fSAndroid Build Coastguard Worker           .WithHelp("Specify a file descriptor for reading the list of known dirty objects in\n"
204*795d594fSAndroid Build Coastguard Worker                     "the image. The image writer will group them together")
205*795d594fSAndroid Build Coastguard Worker           .IntoKey(M::DirtyImageObjectsFd)
206*795d594fSAndroid Build Coastguard Worker       .Define("--updatable-bcp-packages-file=_")
207*795d594fSAndroid Build Coastguard Worker           .WithType<std::string>()
208*795d594fSAndroid Build Coastguard Worker           .WithHelp("Deprecated. No longer takes effect.")
209*795d594fSAndroid Build Coastguard Worker           .IntoKey(M::UpdatableBcpPackagesFile)
210*795d594fSAndroid Build Coastguard Worker       .Define("--updatable-bcp-packages-fd=_")
211*795d594fSAndroid Build Coastguard Worker           .WithType<int>()
212*795d594fSAndroid Build Coastguard Worker           .WithHelp("Deprecated. No longer takes effect.")
213*795d594fSAndroid Build Coastguard Worker           .IntoKey(M::UpdatableBcpPackagesFd)
214*795d594fSAndroid Build Coastguard Worker       .Define("--image-format=_")
215*795d594fSAndroid Build Coastguard Worker           .WithType<ImageHeader::StorageMode>()
216*795d594fSAndroid Build Coastguard Worker           .WithValueMap({{"lz4", ImageHeader::kStorageModeLZ4},
217*795d594fSAndroid Build Coastguard Worker                          {"lz4hc", ImageHeader::kStorageModeLZ4HC},
218*795d594fSAndroid Build Coastguard Worker                          {"uncompressed", ImageHeader::kStorageModeUncompressed}})
219*795d594fSAndroid Build Coastguard Worker           .WithHelp("Which format to store the image Defaults to uncompressed. Eg:"
220*795d594fSAndroid Build Coastguard Worker                     " --image-format=lz4")
221*795d594fSAndroid Build Coastguard Worker           .IntoKey(M::ImageFormat);
222*795d594fSAndroid Build Coastguard Worker   // clang-format on
223*795d594fSAndroid Build Coastguard Worker }
224*795d594fSAndroid Build Coastguard Worker 
AddSwapMappings(Builder & builder)225*795d594fSAndroid Build Coastguard Worker static void AddSwapMappings(Builder& builder) {
226*795d594fSAndroid Build Coastguard Worker   // clang-format off
227*795d594fSAndroid Build Coastguard Worker   builder.
228*795d594fSAndroid Build Coastguard Worker       Define("--swap-file=_")
229*795d594fSAndroid Build Coastguard Worker           .WithType<std::string>()
230*795d594fSAndroid Build Coastguard Worker           .WithHelp("Specify a file to use for swap. Eg: --swap-file=/data/tmp/swap.001")
231*795d594fSAndroid Build Coastguard Worker           .IntoKey(M::SwapFile)
232*795d594fSAndroid Build Coastguard Worker       .Define("--swap-fd=_")
233*795d594fSAndroid Build Coastguard Worker           .WithType<int>()
234*795d594fSAndroid Build Coastguard Worker           .WithHelp("Specify a file to use for swap by file-descriptor. Eg: --swap-fd=3")
235*795d594fSAndroid Build Coastguard Worker           .IntoKey(M::SwapFileFd)
236*795d594fSAndroid Build Coastguard Worker       .Define("--swap-dex-size-threshold=_")
237*795d594fSAndroid Build Coastguard Worker           .WithType<unsigned int>()
238*795d594fSAndroid Build Coastguard Worker           .WithHelp("specifies the minimum total dex file size in bytes to allow the use of swap.")
239*795d594fSAndroid Build Coastguard Worker           .IntoKey(M::SwapDexSizeThreshold)
240*795d594fSAndroid Build Coastguard Worker       .Define("--swap-dex-count-threshold=_")
241*795d594fSAndroid Build Coastguard Worker           .WithType<unsigned int>()
242*795d594fSAndroid Build Coastguard Worker           .WithHelp("specifies the minimum number of dex file to allow the use of swap.")
243*795d594fSAndroid Build Coastguard Worker           .IntoKey(M::SwapDexCountThreshold);
244*795d594fSAndroid Build Coastguard Worker   // clang-format on
245*795d594fSAndroid Build Coastguard Worker }
246*795d594fSAndroid Build Coastguard Worker 
AddCompilerMappings(Builder & builder)247*795d594fSAndroid Build Coastguard Worker static void AddCompilerMappings(Builder& builder) {
248*795d594fSAndroid Build Coastguard Worker   // clang-format off
249*795d594fSAndroid Build Coastguard Worker   builder.
250*795d594fSAndroid Build Coastguard Worker       Define("--run-passes=_")
251*795d594fSAndroid Build Coastguard Worker           .WithType<std::string>()
252*795d594fSAndroid Build Coastguard Worker           .IntoKey(M::Passes)
253*795d594fSAndroid Build Coastguard Worker       .Define("--profile-file=_")
254*795d594fSAndroid Build Coastguard Worker           .WithType<std::vector<std::string>>().AppendValues()
255*795d594fSAndroid Build Coastguard Worker           .WithHelp("Specify profiler output file to use for compilation using a filename.\n"
256*795d594fSAndroid Build Coastguard Worker                     "When multiple profiles are used, the order matters: If multiple profiles \n"
257*795d594fSAndroid Build Coastguard Worker                     "contain classes and methods of the same dex file with different checksums, \n"
258*795d594fSAndroid Build Coastguard Worker                     "only the classes and methods from the first profile will be used for that \n"
259*795d594fSAndroid Build Coastguard Worker                     "particular dex file.")
260*795d594fSAndroid Build Coastguard Worker           .IntoKey(M::Profile)
261*795d594fSAndroid Build Coastguard Worker       .Define("--profile-file-fd=_")
262*795d594fSAndroid Build Coastguard Worker           .WithType<std::vector<int>>().AppendValues()
263*795d594fSAndroid Build Coastguard Worker           .WithHelp("Specify profiler output file to use for compilation using a file-descriptor.")
264*795d594fSAndroid Build Coastguard Worker           .IntoKey(M::ProfileFd)
265*795d594fSAndroid Build Coastguard Worker       .Define("--no-inline-from=_")
266*795d594fSAndroid Build Coastguard Worker           .WithType<std::string>()
267*795d594fSAndroid Build Coastguard Worker           .IntoKey(M::NoInlineFrom)
268*795d594fSAndroid Build Coastguard Worker       .Define("--preloaded-classes=_")
269*795d594fSAndroid Build Coastguard Worker           .WithType<std::vector<std::string>>().AppendValues()
270*795d594fSAndroid Build Coastguard Worker           .WithHelp("Specify files containing list of classes preloaded in the zygote.")
271*795d594fSAndroid Build Coastguard Worker           .IntoKey(M::PreloadedClasses)
272*795d594fSAndroid Build Coastguard Worker       .Define("--preloaded-classes-fds=_")
273*795d594fSAndroid Build Coastguard Worker           .WithType<std::vector<int>>().AppendValues()
274*795d594fSAndroid Build Coastguard Worker           .WithHelp("Specify files containing list of classes preloaded in the zygote.")
275*795d594fSAndroid Build Coastguard Worker           .IntoKey(M::PreloadedClassesFds);
276*795d594fSAndroid Build Coastguard Worker   // clang-format on
277*795d594fSAndroid Build Coastguard Worker }
278*795d594fSAndroid Build Coastguard Worker 
AddTargetMappings(Builder & builder)279*795d594fSAndroid Build Coastguard Worker static void AddTargetMappings(Builder& builder) {
280*795d594fSAndroid Build Coastguard Worker   // clang-format off
281*795d594fSAndroid Build Coastguard Worker   builder.
282*795d594fSAndroid Build Coastguard Worker       Define("--instruction-set=_")
283*795d594fSAndroid Build Coastguard Worker           .WithType<InstructionSet>()
284*795d594fSAndroid Build Coastguard Worker           .WithHelp("Compile for a particular instruction set.")
285*795d594fSAndroid Build Coastguard Worker           .IntoKey(M::TargetInstructionSet)
286*795d594fSAndroid Build Coastguard Worker       .Define("--instruction-set-variant=_")
287*795d594fSAndroid Build Coastguard Worker           .WithType<std::string>()
288*795d594fSAndroid Build Coastguard Worker           .WithHelp("Specify instruction set features using variant name.\n"
289*795d594fSAndroid Build Coastguard Worker                     "Eg: --instruction-set-variant=silvermont")
290*795d594fSAndroid Build Coastguard Worker           .WithMetavar("{Variant Name}")
291*795d594fSAndroid Build Coastguard Worker           .IntoKey(M::TargetInstructionSetVariant)
292*795d594fSAndroid Build Coastguard Worker       .Define("--instruction-set-features=_")
293*795d594fSAndroid Build Coastguard Worker           .WithType<std::string>()
294*795d594fSAndroid Build Coastguard Worker           .WithHelp("Specify instruction set features.\n"
295*795d594fSAndroid Build Coastguard Worker                     "On target the value 'runtime' can be used to detect features at run time.\n"
296*795d594fSAndroid Build Coastguard Worker                     "If target does not support run-time detection the value 'runtime'\n"
297*795d594fSAndroid Build Coastguard Worker                     "has the same effect as the value 'default'.\n"
298*795d594fSAndroid Build Coastguard Worker                     "Note: the value 'runtime' has no effect if it is used on host.\n"
299*795d594fSAndroid Build Coastguard Worker                     "Example: --instruction-set-features=div\n"
300*795d594fSAndroid Build Coastguard Worker                     "Default: default")
301*795d594fSAndroid Build Coastguard Worker           .IntoKey(M::TargetInstructionSetFeatures);
302*795d594fSAndroid Build Coastguard Worker   // clang-format on
303*795d594fSAndroid Build Coastguard Worker }
304*795d594fSAndroid Build Coastguard Worker 
CreateDex2oatArgumentParser()305*795d594fSAndroid Build Coastguard Worker Parser CreateDex2oatArgumentParser() {
306*795d594fSAndroid Build Coastguard Worker   std::unique_ptr<Builder> parser_builder = std::make_unique<Builder>();
307*795d594fSAndroid Build Coastguard Worker 
308*795d594fSAndroid Build Coastguard Worker   AddInputMappings(*parser_builder);
309*795d594fSAndroid Build Coastguard Worker   AddGeneratedArtifactMappings(*parser_builder);
310*795d594fSAndroid Build Coastguard Worker   AddImageMappings(*parser_builder);
311*795d594fSAndroid Build Coastguard Worker   AddSwapMappings(*parser_builder);
312*795d594fSAndroid Build Coastguard Worker   AddCompilerMappings(*parser_builder);
313*795d594fSAndroid Build Coastguard Worker   AddTargetMappings(*parser_builder);
314*795d594fSAndroid Build Coastguard Worker 
315*795d594fSAndroid Build Coastguard Worker   // clang-format off
316*795d594fSAndroid Build Coastguard Worker   parser_builder->
317*795d594fSAndroid Build Coastguard Worker       Define({"--watch-dog", "--no-watch-dog"})
318*795d594fSAndroid Build Coastguard Worker           .WithHelp("Enable or disable the watchdog timer.")
319*795d594fSAndroid Build Coastguard Worker           .WithValues({true, false})
320*795d594fSAndroid Build Coastguard Worker           .IntoKey(M::Watchdog)
321*795d594fSAndroid Build Coastguard Worker       .Define("--watchdog-timeout=_")
322*795d594fSAndroid Build Coastguard Worker           .WithType<int>()
323*795d594fSAndroid Build Coastguard Worker           .WithHelp("Set the watchdog timeout value in milliseconds.")
324*795d594fSAndroid Build Coastguard Worker           .IntoKey(M::WatchdogTimeout)
325*795d594fSAndroid Build Coastguard Worker       .Define("-j_")
326*795d594fSAndroid Build Coastguard Worker           .WithType<unsigned int>()
327*795d594fSAndroid Build Coastguard Worker           .WithHelp("specifies the number of threads used for compilation. Default is the number\n"
328*795d594fSAndroid Build Coastguard Worker                     "of detected hardware threads available on the host system.")
329*795d594fSAndroid Build Coastguard Worker           .IntoKey(M::Threads)
330*795d594fSAndroid Build Coastguard Worker       .Define("--cpu-set=_")
331*795d594fSAndroid Build Coastguard Worker           .WithType<ParseIntList<','>>()
332*795d594fSAndroid Build Coastguard Worker           .WithHelp("sets the cpu affinitiy to the given <set>. The <set> is a comma separated\n"
333*795d594fSAndroid Build Coastguard Worker                     "list of cpus. Eg: --cpu-set=0,1,2,3")
334*795d594fSAndroid Build Coastguard Worker           .WithMetavar("<set>")
335*795d594fSAndroid Build Coastguard Worker           .IntoKey(M::CpuSet)
336*795d594fSAndroid Build Coastguard Worker       .Define("--android-root=_")
337*795d594fSAndroid Build Coastguard Worker           .WithType<std::string>()
338*795d594fSAndroid Build Coastguard Worker           .WithHelp("Used to locate libraries for portable linking.\n"
339*795d594fSAndroid Build Coastguard Worker                     "Eg: --android-root=out/host/linux-x86\n"
340*795d594fSAndroid Build Coastguard Worker                     "Default: $ANDROID_ROOT")
341*795d594fSAndroid Build Coastguard Worker           .IntoKey(M::AndroidRoot)
342*795d594fSAndroid Build Coastguard Worker       .Define("--host")
343*795d594fSAndroid Build Coastguard Worker           .WithHelp("Run in host mode")
344*795d594fSAndroid Build Coastguard Worker           .IntoKey(M::Host)
345*795d594fSAndroid Build Coastguard Worker       .Define("--avoid-storing-invocation")
346*795d594fSAndroid Build Coastguard Worker           .WithHelp("Avoid storing the invocation args in the key-value store. Used to test\n"
347*795d594fSAndroid Build Coastguard Worker                     "determinism with different args.")
348*795d594fSAndroid Build Coastguard Worker           .IntoKey(M::AvoidStoringInvocation)
349*795d594fSAndroid Build Coastguard Worker       .Define("--very-large-app-threshold=_")
350*795d594fSAndroid Build Coastguard Worker           .WithType<unsigned int>()
351*795d594fSAndroid Build Coastguard Worker           .WithHelp("Specifies the minimum total dex file size in bytes to consider the input\n"
352*795d594fSAndroid Build Coastguard Worker                     "\"very large\" and reduce compilation done.")
353*795d594fSAndroid Build Coastguard Worker           .IntoKey(M::VeryLargeAppThreshold)
354*795d594fSAndroid Build Coastguard Worker       .Define("--force-determinism")
355*795d594fSAndroid Build Coastguard Worker           .WithHelp("Force the compiler to emit a deterministic output")
356*795d594fSAndroid Build Coastguard Worker           .IntoKey(M::ForceDeterminism)
357*795d594fSAndroid Build Coastguard Worker       .Define("--check-linkage-conditions")
358*795d594fSAndroid Build Coastguard Worker           .IntoKey(M::CheckLinkageConditions)
359*795d594fSAndroid Build Coastguard Worker       .Define("--crash-on-linkage-violation")
360*795d594fSAndroid Build Coastguard Worker           .IntoKey(M::CrashOnLinkageViolation)
361*795d594fSAndroid Build Coastguard Worker       .Define("--copy-dex-files=_")
362*795d594fSAndroid Build Coastguard Worker           .WithType<linker::CopyOption>()
363*795d594fSAndroid Build Coastguard Worker           .WithValueMap({{"true", linker::CopyOption::kOnlyIfCompressed},
364*795d594fSAndroid Build Coastguard Worker                          {"false", linker::CopyOption::kNever},
365*795d594fSAndroid Build Coastguard Worker                          {"always", linker::CopyOption::kAlways}})
366*795d594fSAndroid Build Coastguard Worker           .WithHelp("enable|disable copying the dex files into the output vdex.")
367*795d594fSAndroid Build Coastguard Worker           .IntoKey(M::CopyDexFiles)
368*795d594fSAndroid Build Coastguard Worker       .Define("--force-allow-oj-inlines")
369*795d594fSAndroid Build Coastguard Worker           .WithHelp("Disables automatic no-inline for core-oj on host. Has no effect on target."
370*795d594fSAndroid Build Coastguard Worker                     " FOR TESTING USE ONLY! DO NOT DISTRIBUTE BINARIES BUILT WITH THIS OPTION!")
371*795d594fSAndroid Build Coastguard Worker           .IntoKey(M::ForceAllowOjInlines)
372*795d594fSAndroid Build Coastguard Worker       .Define("--write-invocation-to=_")
373*795d594fSAndroid Build Coastguard Worker           .WithHelp("Write the invocation commandline to the given file for later use. Used to\n"
374*795d594fSAndroid Build Coastguard Worker                     "test determinism with different args.")
375*795d594fSAndroid Build Coastguard Worker           .WithType<std::string>()
376*795d594fSAndroid Build Coastguard Worker           .IntoKey(M::InvocationFile)
377*795d594fSAndroid Build Coastguard Worker       .Define("--classpath-dir=_")
378*795d594fSAndroid Build Coastguard Worker           .WithType<std::string>()
379*795d594fSAndroid Build Coastguard Worker           .WithHelp("Directory used to resolve relative class paths.")
380*795d594fSAndroid Build Coastguard Worker           .IntoKey(M::ClasspathDir)
381*795d594fSAndroid Build Coastguard Worker       .Define("--class-loader-context=_")
382*795d594fSAndroid Build Coastguard Worker           .WithType<std::string>()
383*795d594fSAndroid Build Coastguard Worker           .WithHelp("a string specifying the intended runtime loading context for the compiled\n"
384*795d594fSAndroid Build Coastguard Worker                     "dex files.")
385*795d594fSAndroid Build Coastguard Worker           .IntoKey(M::ClassLoaderContext)
386*795d594fSAndroid Build Coastguard Worker       .Define("--class-loader-context-fds=_")
387*795d594fSAndroid Build Coastguard Worker           .WithType<std::string>()
388*795d594fSAndroid Build Coastguard Worker           .WithHelp("a colon-separated list of file descriptors for dex files in\n"
389*795d594fSAndroid Build Coastguard Worker                     "--class-loader-context. Their order must be the same as dex files in a\n"
390*795d594fSAndroid Build Coastguard Worker                     "flattened class loader context")
391*795d594fSAndroid Build Coastguard Worker           .IntoKey(M::ClassLoaderContextFds)
392*795d594fSAndroid Build Coastguard Worker       .Define("--stored-class-loader-context=_")
393*795d594fSAndroid Build Coastguard Worker           .WithType<std::string>()
394*795d594fSAndroid Build Coastguard Worker           .WithHelp("a string specifying the intended runtime loading context that is stored\n"
395*795d594fSAndroid Build Coastguard Worker                     "in the oat file. Overrides --class-loader-context. Note that this ignores\n"
396*795d594fSAndroid Build Coastguard Worker                     "the classpath_dir arg.\n"
397*795d594fSAndroid Build Coastguard Worker                     "\n"
398*795d594fSAndroid Build Coastguard Worker                     "It describes how the class loader chain should be built in order to ensure\n"
399*795d594fSAndroid Build Coastguard Worker                     "classes are resolved during dex2aot as they would be resolved at runtime.\n"
400*795d594fSAndroid Build Coastguard Worker                     "This spec will be encoded in the oat file. If at runtime the dex file is\n"
401*795d594fSAndroid Build Coastguard Worker                     "loaded in a different context, the oat file will be rejected.\n"
402*795d594fSAndroid Build Coastguard Worker                     "\n"
403*795d594fSAndroid Build Coastguard Worker                     "The chain is interpreted in the natural 'parent order', meaning that class\n"
404*795d594fSAndroid Build Coastguard Worker                     "loader 'i+1' will be the parent of class loader 'i'.\n"
405*795d594fSAndroid Build Coastguard Worker                     "The compilation sources will be appended to the classpath of the first class\n"
406*795d594fSAndroid Build Coastguard Worker                     "loader.\n"
407*795d594fSAndroid Build Coastguard Worker                     "\n"
408*795d594fSAndroid Build Coastguard Worker                     "E.g. if the context is 'PCL[lib1.dex];DLC[lib2.dex]' and \n"
409*795d594fSAndroid Build Coastguard Worker                     "--dex-file=src.dex then dex2oat will setup a PathClassLoader with classpath \n"
410*795d594fSAndroid Build Coastguard Worker                     "'lib1.dex:src.dex' and set its parent to a DelegateLastClassLoader with \n"
411*795d594fSAndroid Build Coastguard Worker                     "classpath 'lib2.dex'.\n"
412*795d594fSAndroid Build Coastguard Worker                     "\n"
413*795d594fSAndroid Build Coastguard Worker                     "Note that the compiler will be tolerant if the source dex files specified\n"
414*795d594fSAndroid Build Coastguard Worker                     "with --dex-file are found in the classpath. The source dex files will be\n"
415*795d594fSAndroid Build Coastguard Worker                     "removed from any class loader's classpath possibly resulting in empty\n"
416*795d594fSAndroid Build Coastguard Worker                     "class loaders.\n"
417*795d594fSAndroid Build Coastguard Worker                     "\n"
418*795d594fSAndroid Build Coastguard Worker                     "Example: --class-loader-context=PCL[lib1.dex:lib2.dex];DLC[lib3.dex]")
419*795d594fSAndroid Build Coastguard Worker           .IntoKey(M::StoredClassLoaderContext)
420*795d594fSAndroid Build Coastguard Worker       // TODO(b/325430813): Obsolete argument that only prints a warning if used. Delete altogether.
421*795d594fSAndroid Build Coastguard Worker       .Define("--compact-dex-level=_")
422*795d594fSAndroid Build Coastguard Worker           .WithType<std::string>()
423*795d594fSAndroid Build Coastguard Worker           .IntoKey(M::CompactDexLevel)
424*795d594fSAndroid Build Coastguard Worker       .Define("--runtime-arg _")
425*795d594fSAndroid Build Coastguard Worker           .WithType<std::vector<std::string>>().AppendValues()
426*795d594fSAndroid Build Coastguard Worker           .WithMetavar("{dalvikvm-arg}")
427*795d594fSAndroid Build Coastguard Worker           .WithHelp("used to specify various arguments for the runtime, such as initial heap\n"
428*795d594fSAndroid Build Coastguard Worker                     "size, maximum heap size, and verbose output. Use a separate --runtime-arg\n"
429*795d594fSAndroid Build Coastguard Worker                     "switch for each argument.\n"
430*795d594fSAndroid Build Coastguard Worker                     "Example: --runtime-arg -Xms256m")
431*795d594fSAndroid Build Coastguard Worker           .IntoKey(M::RuntimeOptions)
432*795d594fSAndroid Build Coastguard Worker       .Define("--compilation-reason=_")
433*795d594fSAndroid Build Coastguard Worker           .WithType<std::string>()
434*795d594fSAndroid Build Coastguard Worker           .WithHelp("optional metadata specifying the reason for compiling the apk. If specified,\n"
435*795d594fSAndroid Build Coastguard Worker                     "the string will be embedded verbatim in the key value store of the oat file.\n"
436*795d594fSAndroid Build Coastguard Worker                     "Example: --compilation-reason=install")
437*795d594fSAndroid Build Coastguard Worker           .IntoKey(M::CompilationReason)
438*795d594fSAndroid Build Coastguard Worker       .Define("--compile-individually")
439*795d594fSAndroid Build Coastguard Worker           .WithHelp("Compiles dex files individually, unloading classes in between compiling each"
440*795d594fSAndroid Build Coastguard Worker                     " file.")
441*795d594fSAndroid Build Coastguard Worker           .IntoKey(M::CompileIndividually)
442*795d594fSAndroid Build Coastguard Worker       .Define("--public-sdk=_")
443*795d594fSAndroid Build Coastguard Worker           .WithType<std::string>()
444*795d594fSAndroid Build Coastguard Worker           .IntoKey(M::PublicSdk)
445*795d594fSAndroid Build Coastguard Worker       .Define("--apex-versions=_")
446*795d594fSAndroid Build Coastguard Worker           .WithType<std::string>()
447*795d594fSAndroid Build Coastguard Worker           .WithHelp("Versions of apexes in the boot classpath, separated by '/'")
448*795d594fSAndroid Build Coastguard Worker           .IntoKey(M::ApexVersions)
449*795d594fSAndroid Build Coastguard Worker       .Define("--force-jit-zygote")
450*795d594fSAndroid Build Coastguard Worker           .WithHelp("Optimizes the app to be executed in an environment that uses JIT Zygote.")
451*795d594fSAndroid Build Coastguard Worker           .IntoKey(M::ForceJitZygote)
452*795d594fSAndroid Build Coastguard Worker       .Define("--force-palette-compilation-hooks")
453*795d594fSAndroid Build Coastguard Worker           .WithHelp("Force PaletteNotify{Start,End}Dex2oatCompilation calls.")
454*795d594fSAndroid Build Coastguard Worker           .IntoKey(M::ForcePaletteCompilationHooks)
455*795d594fSAndroid Build Coastguard Worker       .Ignore({
456*795d594fSAndroid Build Coastguard Worker         "--comments=_",
457*795d594fSAndroid Build Coastguard Worker         "--cache-info-fd=_",  // Handled in mark_compact.cc.
458*795d594fSAndroid Build Coastguard Worker         "--compiler-backend",
459*795d594fSAndroid Build Coastguard Worker       });
460*795d594fSAndroid Build Coastguard Worker   // clang-format on
461*795d594fSAndroid Build Coastguard Worker 
462*795d594fSAndroid Build Coastguard Worker   AddCompilerOptionsArgumentParserOptions<Dex2oatArgumentMap>(*parser_builder);
463*795d594fSAndroid Build Coastguard Worker 
464*795d594fSAndroid Build Coastguard Worker   parser_builder->IgnoreUnrecognized(false);
465*795d594fSAndroid Build Coastguard Worker 
466*795d594fSAndroid Build Coastguard Worker   return parser_builder->Build();
467*795d594fSAndroid Build Coastguard Worker }
468*795d594fSAndroid Build Coastguard Worker 
Parse(int argc,const char ** argv,std::string * error_msg)469*795d594fSAndroid Build Coastguard Worker std::unique_ptr<Dex2oatArgumentMap> Dex2oatArgumentMap::Parse(int argc,
470*795d594fSAndroid Build Coastguard Worker                                                               const char** argv,
471*795d594fSAndroid Build Coastguard Worker                                                               std::string* error_msg) {
472*795d594fSAndroid Build Coastguard Worker   Parser parser = CreateDex2oatArgumentParser();
473*795d594fSAndroid Build Coastguard Worker   CmdlineResult parse_result = parser.Parse(argv, argc);
474*795d594fSAndroid Build Coastguard Worker   if (!parse_result.IsSuccess()) {
475*795d594fSAndroid Build Coastguard Worker     *error_msg = parse_result.GetMessage();
476*795d594fSAndroid Build Coastguard Worker     return nullptr;
477*795d594fSAndroid Build Coastguard Worker   }
478*795d594fSAndroid Build Coastguard Worker 
479*795d594fSAndroid Build Coastguard Worker   return std::make_unique<Dex2oatArgumentMap>(parser.ReleaseArgumentsMap());
480*795d594fSAndroid Build Coastguard Worker }
481*795d594fSAndroid Build Coastguard Worker 
482*795d594fSAndroid Build Coastguard Worker #pragma GCC diagnostic pop
483*795d594fSAndroid Build Coastguard Worker }  // namespace art
484