OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "native_client/src/trusted/plugin/pnacl_coordinator.h" | 5 #include "native_client/src/trusted/plugin/pnacl_coordinator.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "native_client/src/include/portability_io.h" | 10 #include "native_client/src/include/portability_io.h" |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 // Helper functions for loading native libs. | 341 // Helper functions for loading native libs. |
342 // Done here to avoid hacking on the manifest parser further... | 342 // Done here to avoid hacking on the manifest parser further... |
343 | 343 |
344 namespace { | 344 namespace { |
345 | 345 |
346 // Fake filename for the object file generated by llvm. | 346 // Fake filename for the object file generated by llvm. |
347 nacl::string GeneratedObjectFileName() { | 347 nacl::string GeneratedObjectFileName() { |
348 return nacl::string("___PNACL_GENERATED"); | 348 return nacl::string("___PNACL_GENERATED"); |
349 } | 349 } |
350 | 350 |
351 string_vector LinkResources(const nacl::string& sandbox_isa, | 351 nacl::string ResourceBaseUrl() { |
352 bool withGenerated) { | 352 nacl::string sandbox_isa = GetSandboxISA(); |
| 353 nacl::string base_url = "pnacl_support/" + sandbox_isa + "/"; |
| 354 return base_url; |
| 355 } |
| 356 |
| 357 string_vector LinkResources(bool withGenerated) { |
353 string_vector results; | 358 string_vector results; |
354 nacl::string base_dir = "pnacl_support/" + sandbox_isa; | |
355 | |
356 // NOTE: order of items == link order. | 359 // NOTE: order of items == link order. |
357 results.push_back(base_dir + "/crtbegin.o"); | |
358 if (withGenerated) { | 360 if (withGenerated) { |
359 results.push_back(GeneratedObjectFileName()); | 361 results.push_back(GeneratedObjectFileName()); |
360 } | 362 } |
361 results.push_back(base_dir + "/libcrt_platform.a"); | 363 results.push_back("libcrt_platform.a"); |
362 results.push_back(base_dir + "/libgcc.a"); | 364 results.push_back("libgcc.a"); |
363 results.push_back(base_dir + "/libgcc_eh.a"); | 365 results.push_back("libgcc_eh.a"); |
364 results.push_back(base_dir + "/crtend.o"); | |
365 return results; | 366 return results; |
366 } | 367 } |
367 | 368 |
368 } // namespace | 369 } // namespace |
369 | 370 |
370 ////////////////////////////////////////////////////////////////////// | 371 ////////////////////////////////////////////////////////////////////// |
371 // Final link callbacks. | 372 // Final link callbacks. |
372 | 373 |
373 namespace { | 374 namespace { |
374 | 375 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 "C", | 423 "C", |
423 &dummy_params, | 424 &dummy_params, |
424 flag.c_str())) { | 425 flag.c_str())) { |
425 AbortLinkThread(p, | 426 AbortLinkThread(p, |
426 "PnaclCoordinator linker AddArg(" + flag + | 427 "PnaclCoordinator linker AddArg(" + flag + |
427 ") failed."); | 428 ") failed."); |
428 } | 429 } |
429 } | 430 } |
430 | 431 |
431 //// Files. | 432 //// Files. |
432 string_vector files = LinkResources(sandbox_isa, true); | 433 string_vector files = LinkResources(true); |
433 PnaclResources* resources = coordinator->resources(); | 434 PnaclResources* resources = coordinator->resources(); |
434 for (string_vector::iterator i = files.begin(), e = files.end(); | 435 for (string_vector::iterator i = files.begin(), e = files.end(); |
435 i != e; ++i) { | 436 i != e; ++i) { |
436 const nacl::string& link_file = *i; | 437 const nacl::string& link_file = *i; |
437 if (coordinator->SubprocessesShouldDie()) { | 438 if (coordinator->SubprocessesShouldDie()) { |
438 NaClThreadExit(1); | 439 NaClThreadExit(1); |
439 } | 440 } |
440 // Add as argument. | 441 // Add as argument. |
441 SrpcParams dummy_params; | 442 SrpcParams dummy_params; |
442 if (!PnaclSrpcLib::InvokeSrpcMethod(browser_interface, | 443 if (!PnaclSrpcLib::InvokeSrpcMethod(browser_interface, |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
578 error_info.SetReport(ERROR_UNKNOWN, | 579 error_info.SetReport(ERROR_UNKNOWN, |
579 "PnaclCoordinator: Failed to download file: " + | 580 "PnaclCoordinator: Failed to download file: " + |
580 pexe_url + "\n"); | 581 pexe_url + "\n"); |
581 ReportLoadError(error_info); | 582 ReportLoadError(error_info); |
582 PnaclNonPpapiError(); | 583 PnaclNonPpapiError(); |
583 } | 584 } |
584 } | 585 } |
585 | 586 |
586 void PnaclCoordinator::BitcodeToNative( | 587 void PnaclCoordinator::BitcodeToNative( |
587 const nacl::string& pexe_url, | 588 const nacl::string& pexe_url, |
588 const nacl::string& llc_url, | |
589 const nacl::string& ld_url, | |
590 const pp::CompletionCallback& finish_callback) { | 589 const pp::CompletionCallback& finish_callback) { |
591 PLUGIN_PRINTF(("PnaclCoordinator::BitcodeToNative (pexe=%s, llc=%s, ld=%s)\n", | 590 PLUGIN_PRINTF(("PnaclCoordinator::BitcodeToNative (pexe=%s)\n", |
592 pexe_url.c_str(), | 591 pexe_url.c_str())); |
593 llc_url.c_str(), | 592 // The base URL for finding all the resources will be obtained from the |
594 ld_url.c_str())); | 593 // PNaCl manifest file. |
595 llc_url_ = llc_url; | 594 // Also, the llc and ld pathnames should be read from the manifest. |
596 ld_url_ = ld_url; | 595 // TODO(sehr): change to use the manifest file when ready. |
| 596 resource_base_url_ = ResourceBaseUrl(); |
| 597 llc_url_ = "llc"; |
| 598 ld_url_ = "ld"; |
597 translate_notify_callback_ = finish_callback; | 599 translate_notify_callback_ = finish_callback; |
598 | 600 |
599 // Steps: | 601 // Steps: |
600 // (1) Schedule downloads for llc, ld nexes, and native libraries (resources). | 602 // (1) Schedule downloads for llc, ld nexes, and native libraries (resources). |
601 // (2) When resources have been downloaded, download pexe. | 603 // (2) When resources have been downloaded, download pexe. |
602 // (3) When pexe download has completed, start translation. | 604 // (3) When pexe download has completed, start translation. |
603 // (4) When llc translation has finished do the link. | 605 // (4) When llc translation has finished do the link. |
604 // (5) When the link is done, we are done, call the finish_callback. | 606 // (5) When the link is done, we are done, call the finish_callback. |
605 // Hand off the SHM file descriptor returned by link. | 607 // Hand off the SHM file descriptor returned by link. |
606 | 608 |
607 // Set up async callbacks for these steps in reverse order. | 609 // Set up async callbacks for these steps in reverse order. |
608 | 610 |
609 translation_unit_.reset(new PnaclTranslationUnit(this)); | 611 translation_unit_.reset(new PnaclTranslationUnit(this)); |
610 | 612 |
611 // When resources loading completes, this causes the pexe download. | 613 // When resources loading completes, this causes the pexe download. |
612 pp::CompletionCallback resources_cb = | 614 pp::CompletionCallback resources_cb = |
613 callback_factory_.NewCallback(&PnaclCoordinator::ResourcesDidLoad, | 615 callback_factory_.NewCallback(&PnaclCoordinator::ResourcesDidLoad, |
614 pexe_url, | 616 pexe_url, |
615 translation_unit_.get()); | 617 translation_unit_.get()); |
616 resources_->AddResourceUrl(llc_url); | 618 resources_->AddResourceUrl(llc_url_); |
617 resources_->AddResourceUrl(ld_url); | 619 resources_->AddResourceUrl(ld_url_); |
618 string_vector link_resources = LinkResources(GetSandboxISA(), false); | 620 string_vector link_resources = LinkResources(false); |
619 for (string_vector::iterator | 621 for (string_vector::iterator |
620 i = link_resources.begin(), e = link_resources.end(); | 622 i = link_resources.begin(), e = link_resources.end(); |
621 i != e; | 623 i != e; |
622 ++i) { | 624 ++i) { |
623 resources_->AddResourceUrl(*i); | 625 resources_->AddResourceUrl(*i); |
624 } | 626 } |
625 resources_->RunWhenAllLoaded(resources_cb); | 627 resources_->RunWhenAllLoaded(resources_cb); |
626 resources_->StartDownloads(); | 628 resources_->StartDownloads(); |
627 } | 629 } |
628 | 630 |
629 } // namespace plugin | 631 } // namespace plugin |
OLD | NEW |