blob: fdbf575c0f02afa3c5e95eb6be723182851509b7 [file] [log] [blame]
Logan Chien8b977d32012-02-21 19:14:55 +08001/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "compilation_unit.h"
18
Logan Chien110bcba2012-04-16 19:11:28 +080019#include "compiled_method.h"
Logan Chien971bf3f2012-05-01 15:47:55 +080020#include "compiler_llvm.h"
Shih-wei Liaod7726e42012-04-20 15:23:36 -070021#include "file.h"
Elliott Hughes0f3c5532012-03-30 14:51:51 -070022#include "instruction_set.h"
Logan Chien8b977d32012-02-21 19:14:55 +080023#include "ir_builder.h"
24#include "logging.h"
Shih-wei Liaod7726e42012-04-20 15:23:36 -070025#include "os.h"
Logan Chien8b977d32012-02-21 19:14:55 +080026
TDYa127d668a062012-04-13 12:36:57 -070027#include "runtime_support_builder_arm.h"
TDYa127b08ed122012-06-05 23:51:19 -070028#include "runtime_support_builder_thumb2.h"
TDYa127d668a062012-04-13 12:36:57 -070029#include "runtime_support_builder_x86.h"
30
Logan Chien8b977d32012-02-21 19:14:55 +080031#include <llvm/ADT/OwningPtr.h>
32#include <llvm/ADT/StringSet.h>
33#include <llvm/ADT/Triple.h>
34#include <llvm/Analysis/CallGraph.h>
35#include <llvm/Analysis/DebugInfo.h>
TDYa127f15b0ab2012-05-11 21:01:36 -070036#include <llvm/Analysis/Dominators.h>
37#include <llvm/Analysis/LoopInfo.h>
Logan Chien8b977d32012-02-21 19:14:55 +080038#include <llvm/Analysis/LoopPass.h>
39#include <llvm/Analysis/RegionPass.h>
TDYa127f15b0ab2012-05-11 21:01:36 -070040#include <llvm/Analysis/ScalarEvolution.h>
Logan Chien8b977d32012-02-21 19:14:55 +080041#include <llvm/Analysis/Verifier.h>
42#include <llvm/Assembly/PrintModulePass.h>
43#include <llvm/Bitcode/ReaderWriter.h>
44#include <llvm/CallGraphSCCPass.h>
Logan Chien110bcba2012-04-16 19:11:28 +080045#include <llvm/CodeGen/MachineFrameInfo.h>
46#include <llvm/CodeGen/MachineFunction.h>
47#include <llvm/CodeGen/MachineFunctionPass.h>
Logan Chien8b977d32012-02-21 19:14:55 +080048#include <llvm/DerivedTypes.h>
49#include <llvm/LLVMContext.h>
Logan Chien8b977d32012-02-21 19:14:55 +080050#include <llvm/Module.h>
Logan Chien971bf3f2012-05-01 15:47:55 +080051#include <llvm/Object/ObjectFile.h>
Logan Chien8b977d32012-02-21 19:14:55 +080052#include <llvm/PassManager.h>
53#include <llvm/Support/Debug.h>
Logan Chien971bf3f2012-05-01 15:47:55 +080054#include <llvm/Support/ELF.h>
Logan Chien8b977d32012-02-21 19:14:55 +080055#include <llvm/Support/FormattedStream.h>
56#include <llvm/Support/ManagedStatic.h>
Shih-wei Liaod7726e42012-04-20 15:23:36 -070057#include <llvm/Support/MemoryBuffer.h>
Logan Chien8b977d32012-02-21 19:14:55 +080058#include <llvm/Support/PassNameParser.h>
59#include <llvm/Support/PluginLoader.h>
60#include <llvm/Support/PrettyStackTrace.h>
61#include <llvm/Support/Signals.h>
62#include <llvm/Support/SystemUtils.h>
63#include <llvm/Support/TargetRegistry.h>
64#include <llvm/Support/TargetSelect.h>
65#include <llvm/Support/ToolOutputFile.h>
66#include <llvm/Support/raw_ostream.h>
Shih-wei Liaod7726e42012-04-20 15:23:36 -070067#include <llvm/Support/system_error.h>
Logan Chien8b977d32012-02-21 19:14:55 +080068#include <llvm/Target/TargetData.h>
69#include <llvm/Target/TargetLibraryInfo.h>
70#include <llvm/Target/TargetMachine.h>
Shih-wei Liaof1cb9a52012-04-20 01:49:18 -070071#include <llvm/Transforms/IPO.h>
Logan Chien8b977d32012-02-21 19:14:55 +080072#include <llvm/Transforms/IPO/PassManagerBuilder.h>
TDYa127f15b0ab2012-05-11 21:01:36 -070073#include <llvm/Transforms/Scalar.h>
Logan Chien8b977d32012-02-21 19:14:55 +080074
Shih-wei Liaod7726e42012-04-20 15:23:36 -070075#include <sys/types.h>
76#include <sys/wait.h>
77#include <unistd.h>
78
Logan Chien8b977d32012-02-21 19:14:55 +080079#include <string>
80
Logan Chien110bcba2012-04-16 19:11:28 +080081namespace {
82
TDYa127f15b0ab2012-05-11 21:01:36 -070083// TODO: We may need something to manage these passes.
84// TODO: We need high-level IR to analysis and do this at the IRBuilder level.
85class AddSuspendCheckToLoopLatchPass : public llvm::LoopPass {
86 public:
87 static char ID;
88
89 AddSuspendCheckToLoopLatchPass() : llvm::LoopPass(ID), irb_(NULL) {
90 LOG(FATAL) << "Unexpected instantiation of AddSuspendCheckToLoopLatchPass";
91 // NOTE: We have to declare this constructor for llvm::RegisterPass, but
92 // this constructor won't work because we have no information on
93 // IRBuilder. Thus, we should place a LOG(FATAL) here.
94 }
95
96 AddSuspendCheckToLoopLatchPass(art::compiler_llvm::IRBuilder* irb)
97 : llvm::LoopPass(ID), irb_(irb) {
98 }
99
100 virtual void getAnalysisUsage(llvm::AnalysisUsage &AU) const {
101 AU.addRequiredID(llvm::LoopSimplifyID);
102
Shih-wei Liaoba67d7d2012-06-23 18:48:04 -0700103 AU.addPreserved<llvm::DominatorTree>();
TDYa127f15b0ab2012-05-11 21:01:36 -0700104 AU.addPreserved<llvm::LoopInfo>();
Shih-wei Liaoba67d7d2012-06-23 18:48:04 -0700105 AU.addPreservedID(llvm::LoopSimplifyID);
TDYa127f15b0ab2012-05-11 21:01:36 -0700106 AU.addPreserved<llvm::ScalarEvolution>();
107 AU.addPreservedID(llvm::BreakCriticalEdgesID);
108 }
109
110 virtual bool runOnLoop(llvm::Loop *loop, llvm::LPPassManager &lpm) {
111 CHECK_EQ(loop->getNumBackEdges(), 1U) << "Loop must be simplified!";
112 llvm::BasicBlock* bb = loop->getLoopLatch();
113 CHECK_NE(bb, static_cast<void*>(NULL)) << "A single loop latch must exist.";
114
Shih-wei Liaoba67d7d2012-06-23 18:48:04 -0700115 irb_->SetInsertPoint(bb->getTerminator());
TDYa127f15b0ab2012-05-11 21:01:36 -0700116
Shih-wei Liaoba67d7d2012-06-23 18:48:04 -0700117 using art::compiler_llvm::runtime_support::TestSuspend;
118 llvm::Value* runtime_func = irb_->GetRuntime(TestSuspend);
119 irb_->CreateCall(runtime_func, irb_->getJNull());
TDYa127f15b0ab2012-05-11 21:01:36 -0700120
121 return true;
122 }
123
124 private:
125 art::compiler_llvm::IRBuilder* irb_;
126};
127
128char AddSuspendCheckToLoopLatchPass::ID = 0;
129
130llvm::RegisterPass<AddSuspendCheckToLoopLatchPass> reg_add_suspend_check_to_loop_latch_pass_(
131 "add-suspend-check-to-loop-latch", "Add suspend check to loop latch pass", false, false);
132
133
Logan Chien110bcba2012-04-16 19:11:28 +0800134} // end anonymous namespace
135
Logan Chien8b977d32012-02-21 19:14:55 +0800136namespace art {
137namespace compiler_llvm {
138
139llvm::Module* makeLLVMModuleContents(llvm::Module* module);
140
141
Logan Chien971bf3f2012-05-01 15:47:55 +0800142CompilationUnit::CompilationUnit(const CompilerLLVM* compiler_llvm,
143 size_t cunit_idx)
144: compiler_llvm_(compiler_llvm), cunit_idx_(cunit_idx),
145 context_(new llvm::LLVMContext()) {
Logan Chien8b977d32012-02-21 19:14:55 +0800146
147 // Create the module and include the runtime function declaration
148 module_ = new llvm::Module("art", *context_);
149 makeLLVMModuleContents(module_);
150
151 // Create IRBuilder
152 irb_.reset(new IRBuilder(*context_, *module_));
TDYa127d668a062012-04-13 12:36:57 -0700153
154 // We always need a switch case, so just use a normal function.
Logan Chien971bf3f2012-05-01 15:47:55 +0800155 switch(GetInstructionSet()) {
TDYa127b08ed122012-06-05 23:51:19 -0700156 default:
157 runtime_support_.reset(new RuntimeSupportBuilder(*context_, *module_, *irb_));
158 break;
TDYa127d668a062012-04-13 12:36:57 -0700159 case kArm:
TDYa127d668a062012-04-13 12:36:57 -0700160 runtime_support_.reset(new RuntimeSupportBuilderARM(*context_, *module_, *irb_));
161 break;
TDYa127b08ed122012-06-05 23:51:19 -0700162 case kThumb2:
163 runtime_support_.reset(new RuntimeSupportBuilderThumb2(*context_, *module_, *irb_));
164 break;
TDYa127d668a062012-04-13 12:36:57 -0700165 case kX86:
166 runtime_support_.reset(new RuntimeSupportBuilderX86(*context_, *module_, *irb_));
167 break;
168 }
169
Shih-wei Liaoba67d7d2012-06-23 18:48:04 -0700170 runtime_support_->OptimizeRuntimeSupport();
171
TDYa127d668a062012-04-13 12:36:57 -0700172 irb_->SetRuntimeSupport(runtime_support_.get());
Logan Chien8b977d32012-02-21 19:14:55 +0800173}
174
175
176CompilationUnit::~CompilationUnit() {
177}
178
179
Logan Chien971bf3f2012-05-01 15:47:55 +0800180InstructionSet CompilationUnit::GetInstructionSet() const {
181 return compiler_llvm_->GetInstructionSet();
Logan Chien8b977d32012-02-21 19:14:55 +0800182}
183
184
Logan Chien971bf3f2012-05-01 15:47:55 +0800185bool CompilationUnit::Materialize() {
186 std::string elf_image;
Logan Chien110bcba2012-04-16 19:11:28 +0800187
Logan Chien971bf3f2012-05-01 15:47:55 +0800188 // Compile and prelink llvm::Module
189 if (!MaterializeToString(elf_image)) {
190 LOG(ERROR) << "Failed to materialize compilation unit " << cunit_idx_;
191 DeleteResources();
192 return false;
Logan Chien110bcba2012-04-16 19:11:28 +0800193 }
Logan Chien971bf3f2012-05-01 15:47:55 +0800194
195#if 0
196 // Dump the ELF image for debugging
197 std::string filename(StringPrintf("%s/Art%zu.elf",
198 GetArtCacheOrDie(GetAndroidData()).c_str(),
199 cunit_idx_));
200 UniquePtr<File> output(OS::OpenFile(filename.c_str(), true));
201 output->WriteFully(elf_image.data(), elf_image.size());
202#endif
203
204 // Extract the .text section and prelink the code
205 if (!ExtractCodeAndPrelink(elf_image)) {
206 LOG(ERROR) << "Failed to extract code from compilation unit " << cunit_idx_;
207 DeleteResources();
208 return false;
209 }
210
211 DeleteResources();
212 return true;
Logan Chien110bcba2012-04-16 19:11:28 +0800213}
214
Logan Chien971bf3f2012-05-01 15:47:55 +0800215
216bool CompilationUnit::MaterializeToString(std::string& str_buffer) {
217 llvm::raw_string_ostream str_os(str_buffer);
218 return MaterializeToRawOStream(str_os);
219}
220
221
222bool CompilationUnit::MaterializeToRawOStream(llvm::raw_ostream& out_stream) {
Shih-wei Liaod7726e42012-04-20 15:23:36 -0700223 // Lookup the LLVM target
224 char const* target_triple = NULL;
Shih-wei Liao53519bf2012-06-17 03:45:00 -0700225 char const* target_cpu = "";
Shih-wei Liaod7726e42012-04-20 15:23:36 -0700226 char const* target_attr = NULL;
227
Logan Chien971bf3f2012-05-01 15:47:55 +0800228 InstructionSet insn_set = GetInstructionSet();
229 switch (insn_set) {
Shih-wei Liaod7726e42012-04-20 15:23:36 -0700230 case kThumb2:
231 target_triple = "thumb-none-linux-gnueabi";
Shih-wei Liao53519bf2012-06-17 03:45:00 -0700232 target_cpu = "cortex-a9";
TDYa127b08ed122012-06-05 23:51:19 -0700233 target_attr = "+thumb2,+neon,+neonfp,+vfp3,+db";
Shih-wei Liaod7726e42012-04-20 15:23:36 -0700234 break;
235
236 case kArm:
237 target_triple = "armv7-none-linux-gnueabi";
Shih-wei Liao53519bf2012-06-17 03:45:00 -0700238 // TODO: Fix for Nexus S.
239 target_cpu = "cortex-a9";
Shih-wei Liaod7726e42012-04-20 15:23:36 -0700240 // TODO: Fix for Xoom.
TDYa127b08ed122012-06-05 23:51:19 -0700241 target_attr = "+v7,+neon,+neonfp,+vfp3,+db";
Shih-wei Liaod7726e42012-04-20 15:23:36 -0700242 break;
243
244 case kX86:
245 target_triple = "i386-pc-linux-gnu";
246 target_attr = "";
247 break;
248
249 case kMips:
250 target_triple = "mipsel-unknown-linux";
251 target_attr = "mips32r2";
252 break;
253
254 default:
Logan Chien971bf3f2012-05-01 15:47:55 +0800255 LOG(FATAL) << "Unknown instruction set: " << insn_set;
Shih-wei Liaod7726e42012-04-20 15:23:36 -0700256 }
257
258 std::string errmsg;
259 llvm::Target const* target =
260 llvm::TargetRegistry::lookupTarget(target_triple, errmsg);
261
262 CHECK(target != NULL) << errmsg;
263
264 // Target options
265 llvm::TargetOptions target_options;
266 target_options.FloatABIType = llvm::FloatABI::Soft;
267 target_options.NoFramePointerElim = true;
268 target_options.NoFramePointerElimNonLeaf = true;
269 target_options.UseSoftFloat = false;
TDYa1273978da52012-05-19 07:45:39 -0700270 target_options.EnableFastISel = false;
Shih-wei Liaod7726e42012-04-20 15:23:36 -0700271
272 // Create the llvm::TargetMachine
Logan Chienb6bed0b2012-05-04 15:03:56 +0800273 llvm::OwningPtr<llvm::TargetMachine> target_machine(
Shih-wei Liao53519bf2012-06-17 03:45:00 -0700274 target->createTargetMachine(target_triple, target_cpu, target_attr, target_options,
Shih-wei Liaod7726e42012-04-20 15:23:36 -0700275 llvm::Reloc::Static, llvm::CodeModel::Small,
Shih-wei Liaodac5eb22012-06-03 14:06:04 -0700276 llvm::CodeGenOpt::Aggressive));
Shih-wei Liaod7726e42012-04-20 15:23:36 -0700277
Logan Chienb6bed0b2012-05-04 15:03:56 +0800278 CHECK(target_machine.get() != NULL) << "Failed to create target machine";
Shih-wei Liaod7726e42012-04-20 15:23:36 -0700279
280 // Add target data
281 llvm::TargetData const* target_data = target_machine->getTargetData();
282
283 // PassManager for code generation passes
284 llvm::PassManager pm;
285 pm.add(new llvm::TargetData(*target_data));
286
287 // FunctionPassManager for optimization pass
Logan Chien799ef4f2012-04-23 00:17:47 +0800288 llvm::FunctionPassManager fpm(module_);
Shih-wei Liaod7726e42012-04-20 15:23:36 -0700289 fpm.add(new llvm::TargetData(*target_data));
290
TDYa127f15b0ab2012-05-11 21:01:36 -0700291 if (bitcode_filename_.empty()) {
292 // If we don't need write the bitcode to file, add the AddSuspendCheckToLoopLatchPass to the
293 // regular FunctionPass.
294 fpm.add(new ::AddSuspendCheckToLoopLatchPass(irb_.get()));
295 } else {
296 // Run AddSuspendCheckToLoopLatchPass before we write the bitcode to file.
297 llvm::FunctionPassManager fpm2(module_);
298 fpm2.add(new ::AddSuspendCheckToLoopLatchPass(irb_.get()));
299 fpm2.doInitialization();
300 for (llvm::Module::iterator F = module_->begin(), E = module_->end();
301 F != E; ++F) {
302 fpm2.run(*F);
303 }
304 fpm2.doFinalization();
305
306
307 // Write bitcode to file
308 std::string errmsg;
309
310 llvm::OwningPtr<llvm::tool_output_file> out_file(
311 new llvm::tool_output_file(bitcode_filename_.c_str(), errmsg,
312 llvm::raw_fd_ostream::F_Binary));
313
314
315 if (!errmsg.empty()) {
316 LOG(ERROR) << "Failed to create bitcode output file: " << errmsg;
317 return false;
318 }
319
320 llvm::WriteBitcodeToFile(module_, out_file->os());
321 out_file->keep();
322 }
323
Shih-wei Liaod7726e42012-04-20 15:23:36 -0700324 // Add optimization pass
325 llvm::PassManagerBuilder pm_builder;
Shih-wei Liaoe0e40242012-05-08 01:04:03 -0700326 //pm_builder.Inliner = llvm::createFunctionInliningPass();
Shih-wei Liaoba67d7d2012-06-23 18:48:04 -0700327 pm_builder.Inliner = llvm::createAlwaysInlinerPass();
Shih-wei Liao415576b2012-04-23 15:28:53 -0700328 //pm_builder.Inliner = llvm::createPartialInliningPass();
329 pm_builder.OptLevel = 3;
Shih-wei Liaod7726e42012-04-20 15:23:36 -0700330 pm_builder.DisableSimplifyLibCalls = 1;
TDYa127e4c2ccc2012-05-13 21:10:36 -0700331 pm_builder.DisableUnitAtATime = 1;
Shih-wei Liaod7726e42012-04-20 15:23:36 -0700332 pm_builder.populateFunctionPassManager(fpm);
TDYa127ce9c3172012-05-15 06:09:27 -0700333 pm_builder.populateModulePassManager(pm);
334 pm.add(llvm::createStripDeadPrototypesPass());
Shih-wei Liaod7726e42012-04-20 15:23:36 -0700335
336 // Add passes to emit ELF image
337 {
Logan Chien08e1ba32012-05-08 15:08:51 +0800338 llvm::formatted_raw_ostream formatted_os(out_stream, false);
Shih-wei Liaod7726e42012-04-20 15:23:36 -0700339
340 // Ask the target to add backend passes as necessary.
341 if (target_machine->addPassesToEmitFile(pm,
342 formatted_os,
343 llvm::TargetMachine::CGFT_ObjectFile,
344 true)) {
345 LOG(FATAL) << "Unable to generate ELF for this target";
346 return false;
347 }
348
Shih-wei Liaod7726e42012-04-20 15:23:36 -0700349 // Run the per-function optimization
350 fpm.doInitialization();
Logan Chien799ef4f2012-04-23 00:17:47 +0800351 for (llvm::Module::iterator F = module_->begin(), E = module_->end();
Shih-wei Liaod7726e42012-04-20 15:23:36 -0700352 F != E; ++F) {
353 fpm.run(*F);
354 }
355 fpm.doFinalization();
356
357 // Run the code generation passes
Logan Chien799ef4f2012-04-23 00:17:47 +0800358 pm.run(*module_);
Shih-wei Liaod7726e42012-04-20 15:23:36 -0700359 }
360
361 return true;
362}
Logan Chien110bcba2012-04-16 19:11:28 +0800363
Logan Chien971bf3f2012-05-01 15:47:55 +0800364
365bool CompilationUnit::ExtractCodeAndPrelink(const std::string& elf_image) {
366 llvm::OwningPtr<llvm::MemoryBuffer> elf_image_buff(
367 llvm::MemoryBuffer::getMemBuffer(llvm::StringRef(elf_image.data(),
368 elf_image.size())));
369
370 llvm::OwningPtr<llvm::object::ObjectFile> elf_file(
371 llvm::object::ObjectFile::createELFObjectFile(elf_image_buff.take()));
372
373 llvm::error_code ec;
374
375 const ProcedureLinkageTable& plt = compiler_llvm_->GetProcedureLinkageTable();
376
377 for (llvm::object::section_iterator
378 sec_iter = elf_file->begin_sections(),
379 sec_end = elf_file->end_sections();
380 sec_iter != sec_end; sec_iter.increment(ec)) {
381
382 CHECK(ec == 0) << "Failed to read section because " << ec.message();
383
384 // Read the section information
385 llvm::StringRef name;
386 uint64_t alignment = 0u;
387 uint64_t size = 0u;
388
389 CHECK(sec_iter->getName(name) == 0);
390 CHECK(sec_iter->getSize(size) == 0);
391 CHECK(sec_iter->getAlignment(alignment) == 0);
392
393 if (name == ".data" || name == ".bss" || name == ".rodata") {
394 if (size > 0) {
395 LOG(FATAL) << "Compilation unit " << cunit_idx_ << " has non-empty "
396 << name.str() << " section";
397 }
398
399 } else if (name == "" || name == ".rel.text" ||
400 name == ".ARM.attributes" || name == ".symtab" ||
401 name == ".strtab" || name == ".shstrtab") {
402 // We can ignore these sections. We don't have to copy them into
403 // the result Oat file.
404
405 } else if (name == ".text") {
406 // Ensure the alignment requirement is less than or equal to
407 // kArchAlignment
408 CheckCodeAlign(alignment);
409
410 // Copy the compiled code
411 llvm::StringRef contents;
412 CHECK(sec_iter->getContents(contents) == 0);
413
414 copy(contents.data(),
415 contents.data() + contents.size(),
416 back_inserter(compiled_code_));
417
418 // Prelink the compiled code
419 for (llvm::object::relocation_iterator
420 rel_iter = sec_iter->begin_relocations(),
421 rel_end = sec_iter->end_relocations(); rel_iter != rel_end;
422 rel_iter.increment(ec)) {
423
424 CHECK(ec == 0) << "Failed to read relocation because " << ec.message();
425
426 // Read the relocation information
427 llvm::object::SymbolRef sym_ref;
428 uint64_t rel_offset = 0;
429 uint64_t rel_type = 0;
430 int64_t rel_addend = 0;
431
432 CHECK(rel_iter->getSymbol(sym_ref) == 0);
433 CHECK(rel_iter->getOffset(rel_offset) == 0);
434 CHECK(rel_iter->getType(rel_type) == 0);
435 CHECK(rel_iter->getAdditionalInfo(rel_addend) == 0);
436
437 // Read the symbol related to this relocation fixup
438 llvm::StringRef sym_name;
439 CHECK(sym_ref.getName(sym_name) == 0);
440
441 // Relocate the fixup.
442 // TODO: Support more relocation type.
443 CHECK(rel_type == llvm::ELF::R_ARM_ABS32);
444 CHECK_LE(rel_offset + 4, compiled_code_.size());
445
446 uintptr_t dest_addr = plt.GetEntryAddress(sym_name.str().c_str());
447 uintptr_t final_addr = dest_addr + rel_addend;
448 compiled_code_[rel_offset] = final_addr & 0xff;
449 compiled_code_[rel_offset + 1] = (final_addr >> 8) & 0xff;
450 compiled_code_[rel_offset + 2] = (final_addr >> 16) & 0xff;
451 compiled_code_[rel_offset + 3] = (final_addr >> 24) & 0xff;
452 }
453
454 } else {
455 LOG(WARNING) << "Unexpected section: " << name.str();
456 }
457 }
458
459 return true;
460}
461
462
463// Check whether the align is less than or equal to the code alignment of
464// that architecture. Since the Oat writer only guarantee that the compiled
465// method being aligned to kArchAlignment, we have no way to align the ELf
466// section if the section alignment is greater than kArchAlignment.
467void CompilationUnit::CheckCodeAlign(uint32_t align) const {
468 InstructionSet insn_set = GetInstructionSet();
469 switch (insn_set) {
470 case kThumb2:
471 case kArm:
472 CHECK_LE(align, static_cast<uint32_t>(kArmAlignment));
473 break;
474
475 case kX86:
476 CHECK_LE(align, static_cast<uint32_t>(kX86Alignment));
477 break;
478
479 case kMips:
480 CHECK_LE(align, static_cast<uint32_t>(kMipsAlignment));
481 break;
482
483 default:
484 LOG(FATAL) << "Unknown instruction set: " << insn_set;
485 }
486}
487
488
Logan Chien8b977d32012-02-21 19:14:55 +0800489} // namespace compiler_llvm
490} // namespace art