Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


Minor compile warning fixup and error checks
[palacios.git] / gears / service_setup / compile-for-static-user-level-injection.pl
1 #!/usr/bin/perl -w
2
3 use Getopt::Long;
4
5 &GetOptions(32=>\$m32, 64=>\$m64, "output=s"=>\$mod);
6
7 $#ARGV >= 0 or die "usage: compile-for-static-user-level-injection.pl [-32|-64] [--output=module_name] source.c+ [lib.a]*\n";
8
9 if (!$m32 && !$m64) {
10   print "Assuming 32 bit.  Use -64 to override\n";
11   $m32=1;
12 }
13
14 if (!$mod) { 
15   print "No module name given, assuming a.tooth\n";
16   $mod = "a.tooth";
17 }
18
19 if ($m32) { 
20   $gopt = "-m32";
21   $lopt = "-melf_i386 --oformat elf32-i386";
22
23
24 if ($m64) { 
25   $gopt = "-m64";
26   $lopt = "-melf_x86_64 --oformat elf64-x86-64";
27 }
28
29
30 $linkerscript = <<END;
31 SECTIONS
32 {
33 /* Must be on a page boundary */
34 /* Should link like ld -z max-page-size=4096 -T ld.script ... */
35 /* If object file is -fPIC, then it shouldn't matter where we load it */
36   . = 0x1000;   
37 /* Text, data, and bss squished together */
38   .text : { *(.text) }
39   .data : { *(.data) }
40   .bss : { *(.bss) }
41 /* Result will be one load group marked RWX */
42 }
43 END
44
45
46
47 @stems=grep(/.*\.c$/,@ARGV);
48 @libs=grep(/.*\.a$/,@ARGV);
49
50 map { $_ =~ s/\.c$//g} @stems;
51
52 print "Compiling...\n";
53 foreach $s (@stems) { 
54   system("gcc $gopt -fPIE -Wa,-R -c $s.c -nostartfiles -nodefaultlibs -nostdlib -static -o $s.o") == 0 
55    or die "Compilation of $s.c failed\n";
56   system("gcc $gopt -fPIE -Wa,-R -S $s.c -nostartfiles -nodefaultlibs -nostdlib -static -o $s.s") == 0 
57    or die "Compilation of $s.c failed\n";
58 }
59 print "Compilation done.\n";
60
61 open(W,">.linker_script");
62 print W $linkerscript;
63 close(W);
64
65 print "Linking...\n";
66
67 $rc=system("ld $lopt -z max-page-size=4096 -T .linker_script ".join(" ",map { "$_.o" } @stems)." ".join(" ",@libs)." -o $mod\n");
68
69 unlink ".linker_script";
70
71 $rc==0 or die "Linking of $mod failed\n";
72
73 print "Linking of $mod completed.  Done.\n";
74
75 open(E,"readelf -h $mod |");
76 while (<E>) { 
77   if (/^\s*Entry point address:\s+(\S+)$/) {
78     print "Entry point relative to beginning of file: $1\n";
79     last;
80   }
81 }
82 close(E);
83