4
4
#include <vector>
5
5
#include <string>
6
6
#include "llvm/Support/FileSystem.h"
7
+ #include "llvm/Support/Path.h"
7
8
8
9
#ifdef ONLY_LD
9
10
#define LD_CAT EosioLdToolCategory
@@ -400,24 +401,52 @@ static void GetCompDefaults(std::vector<std::string>& copts) {
400
401
#ifdef ONLY_LD
401
402
static void GetLdDefaults(std::vector<std::string>& ldopts) {
402
403
if (!fnative_opt) {
403
- if (fuse_main_opt)
404
- ldopts.emplace_back("-e main");
405
- else {
406
- if (fquery_opt) {
407
- // fill in base entry point for query wasm
408
- ldopts.emplace_back("-e apply");
409
- } else
410
- ldopts.emplace_back("-e apply");
411
- }
412
404
ldopts.emplace_back("--gc-sections");
413
405
ldopts.emplace_back("--strip-all");
414
406
ldopts.emplace_back("-zstack-size="+std::string("${EOSIO_STACK_SIZE}"));
415
407
ldopts.emplace_back("--merge-data-segments");
408
+ if (fquery_opt) {
409
+ ldopts.emplace_back("--export-table");
410
+ ldopts.emplace_back("-other-model");
411
+ ldopts.emplace_back("--only-export \"*:table\"");
412
+ ldopts.emplace_back("--only-export \"*:memory\"");
413
+ if (fuse_main_opt)
414
+ ldopts.emplace_back("-e main");
415
+ else
416
+ ldopts.emplace_back("-e initialize ");
417
+ ldopts.emplace_back("-export startup ");
418
+ ldopts.emplace_back("-export create_request ");
419
+ ldopts.emplace_back("-export decode_response ");
420
+ ldopts.emplace_back("-export describe_request ");
421
+ ldopts.emplace_back("-export describe_response ");
422
+ ldopts.emplace_back("--only-export \"initialize:function\"");
423
+ ldopts.emplace_back("--only-export \"startup:function\"");
424
+ ldopts.emplace_back("--only-export \"create_request:function\"");
425
+ ldopts.emplace_back("--only-export \"decode_response:function\"");
426
+ ldopts.emplace_back("--only-export \"describe_request:function\"");
427
+ ldopts.emplace_back("--only-export \"describe_response:function\"");
428
+ } else {
429
+ if (fuse_main_opt)
430
+ ldopts.emplace_back("-e main");
431
+ else
432
+ ldopts.emplace_back("-e apply");
433
+ ldopts.emplace_back("--only-export \"apply:function\"");
434
+ }
435
+ ldopts.emplace_back("-lc++ -lc -leosio");
436
+ if (use_old_malloc_opt)
437
+ ldopts.emplace_back("-leosio_malloc");
438
+ else
439
+ ldopts.emplace_back("-leosio_dsm");
440
+
441
+ if (use_rt_opt || fquery_opt)
442
+ ldopts.emplace_back("-lrt -lsf");
443
+
416
444
} else {
417
445
#ifdef __APPLE__
418
446
ldopts.emplace_back("-arch x86_64 -macosx_version_min 10.13 -framework Foundation -framework System");
419
447
#endif
420
448
ldopts.emplace_back("-static");
449
+ ldopts.emplace_back("-lnative_c++ -lnative_c -lnative_eosio -lnative");
421
450
}
422
451
}
423
452
#endif
@@ -448,6 +477,11 @@ static Options CreateOptions(bool add_defaults=true) {
448
477
GetLdDefaults(ldopts);
449
478
#endif
450
479
}
480
+
481
+ #ifndef ONLY_LD
482
+ if (fquery_opt)
483
+ ldopts.emplace_back("-fquery");
484
+ #endif
451
485
452
486
if (!pp_path_opt.empty())
453
487
pp_dir = pp_path_opt;
@@ -677,10 +711,27 @@ static Options CreateOptions(bool add_defaults=true) {
677
711
}
678
712
if (o_opt.empty()) {
679
713
#ifndef ONLY_LD
680
- ldopts.emplace_back("a.out");
714
+ if (inputs.size() == 1) {
715
+ llvm::SmallString<256> fn = llvm::sys::path::filename(inputs[0]);
716
+ llvm::SmallString<256> fn2 = fn;
717
+ llvm::sys::path::replace_extension(fn, ".wasm");
718
+ output_fn = fn.str();
719
+ llvm::SmallString<256> res;
720
+ llvm::sys::path::system_temp_directory(true, res);
721
+ ldopts.emplace_back(std::string(std::string(res.str())+"/"+std::string(fn2.str())+".o"));
722
+ } else {
723
+ ldopts.emplace_back("a.out");
724
+ }
681
725
#endif
682
- ldopts.emplace_back("-o a.out");
683
- output_fn = "a.out";
726
+ if (inputs.size() == 1) {
727
+ llvm::SmallString<256> fn = llvm::sys::path::filename(inputs[0]);
728
+ llvm::sys::path::replace_extension(fn, ".wasm");
729
+ ldopts.emplace_back("-o "+output_fn);
730
+ output_fn = fn.str();
731
+ } else {
732
+ ldopts.emplace_back("-o a.out");
733
+ output_fn = "a.out";
734
+ }
684
735
}
685
736
else {
686
737
ldopts.emplace_back("-o "+o_opt);
@@ -733,8 +784,9 @@ static Options CreateOptions(bool add_defaults=true) {
733
784
if (!contract_name.empty())
734
785
abigen_contract = contract_name;
735
786
else {
736
- std::string fn = llvm::sys::path::filename(output_fn);
737
- abigen_contract = fn.substr(0, fn.rfind(".wasm"));
787
+ llvm::SmallString<256> fn = llvm::sys::path::filename(output_fn);
788
+ llvm::sys::path::replace_extension(fn, "");
789
+ abigen_contract = fn.str();
738
790
}
739
791
740
792
for ( auto resource : resources ) {
@@ -744,29 +796,6 @@ static Options CreateOptions(bool add_defaults=true) {
744
796
ldopts.emplace_back("-fnative");
745
797
if (fuse_main_opt)
746
798
ldopts.emplace_back("-fuse-main");
747
- #else
748
- if (fnative_opt)
749
- ldopts.emplace_back("-lnative_c++ -lnative_c -lnative_eosio -lnative");
750
- else {
751
- ldopts.emplace_back("-lc++ -lc -leosio");
752
- if (use_old_malloc_opt)
753
- ldopts.emplace_back("-leosio_malloc");
754
- else
755
- ldopts.emplace_back("-leosio_dsm");
756
-
757
- if (fquery_opt) {
758
- ldopts.emplace_back("--export-table");
759
- ldopts.emplace_back("--only-export \"*:table\"");
760
- // fill in other exports for "entry points"
761
- //ldopts.emplace_back("--export ");
762
- //ldopts.emplace_back("--only-export \":function\"");
763
- } else {
764
- ldopts.emplace_back("--only-export \"apply:function\"");
765
- }
766
-
767
- }
768
- if ((use_rt_opt && !fnative_opt) || fquery_opt)
769
- ldopts.emplace_back("-lrt -lsf");
770
799
#endif
771
800
return {output_fn, inputs, link, abigen, pp_dir, abigen_output, abigen_contract, copts, ldopts, agopts, agresources, fnative_opt};
772
801
}
0 commit comments