github.com/razvanm/vanadium-go-1.3@v0.0.0-20160721203343-4a65068e5915/src/cmd/6l/obj.c (about) 1 // Inferno utils/6l/obj.c 2 // http://code.google.com/p/inferno-os/source/browse/utils/6l/obj.c 3 // 4 // Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved. 5 // Portions Copyright © 1995-1997 C H Forsyth (forsyth@terzarima.net) 6 // Portions Copyright © 1997-1999 Vita Nuova Limited 7 // Portions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com) 8 // Portions Copyright © 2004,2006 Bruce Ellis 9 // Portions Copyright © 2005-2007 C H Forsyth (forsyth@terzarima.net) 10 // Revisions Copyright © 2000-2007 Lucent Technologies Inc. and others 11 // Portions Copyright © 2009 The Go Authors. All rights reserved. 12 // 13 // Permission is hereby granted, free of charge, to any person obtaining a copy 14 // of this software and associated documentation files (the "Software"), to deal 15 // in the Software without restriction, including without limitation the rights 16 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 17 // copies of the Software, and to permit persons to whom the Software is 18 // furnished to do so, subject to the following conditions: 19 // 20 // The above copyright notice and this permission notice shall be included in 21 // all copies or substantial portions of the Software. 22 // 23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 26 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 28 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 29 // THE SOFTWARE. 30 31 // Reading object files. 32 33 #include "l.h" 34 #include "../ld/lib.h" 35 #include "../ld/elf.h" 36 #include "../ld/macho.h" 37 #include "../ld/dwarf.h" 38 #include "../ld/pe.h" 39 #include <ar.h> 40 41 char* thestring = "amd64"; 42 LinkArch* thelinkarch = &linkamd64; 43 44 void 45 linkarchinit(void) 46 { 47 if(strcmp(getgoarch(), "amd64p32") == 0) 48 thelinkarch = &linkamd64p32; 49 PtrSize = thelinkarch->ptrsize; 50 IntSize = PtrSize; 51 RegSize = thelinkarch->regsize; 52 } 53 54 void 55 archinit(void) 56 { 57 // getgoextlinkenabled is based on GO_EXTLINK_ENABLED when 58 // Go was built; see ../../make.bash. 59 if(linkmode == LinkAuto && strcmp(getgoextlinkenabled(), "0") == 0) 60 linkmode = LinkInternal; 61 62 if(flag_shared) 63 linkmode = LinkExternal; 64 65 switch(HEADTYPE) { 66 default: 67 if(linkmode == LinkAuto) 68 linkmode = LinkInternal; 69 if(linkmode == LinkExternal && strcmp(getgoextlinkenabled(), "1") != 0) 70 sysfatal("cannot use -linkmode=external with -H %s", headstr(HEADTYPE)); 71 break; 72 case Hdarwin: 73 case Hdragonfly: 74 case Hfreebsd: 75 case Hlinux: 76 case Hnacl: 77 case Hnetbsd: 78 case Hopenbsd: 79 case Hsolaris: 80 break; 81 } 82 83 switch(HEADTYPE) { 84 default: 85 diag("unknown -H option"); 86 errorexit(); 87 case Hplan9: /* plan 9 */ 88 HEADR = 32L + 8L; 89 if(INITTEXT == -1) 90 INITTEXT = 0x200000+HEADR; 91 if(INITDAT == -1) 92 INITDAT = 0; 93 if(INITRND == -1) 94 INITRND = 0x200000; 95 break; 96 case Helf: /* elf32 executable */ 97 HEADR = rnd(52L+3*32L, 16); 98 if(INITTEXT == -1) 99 INITTEXT = 0x80110000L; 100 if(INITDAT == -1) 101 INITDAT = 0; 102 if(INITRND == -1) 103 INITRND = 4096; 104 break; 105 case Hdarwin: /* apple MACH */ 106 machoinit(); 107 HEADR = INITIAL_MACHO_HEADR; 108 if(INITRND == -1) 109 INITRND = 4096; 110 if(INITTEXT == -1) 111 INITTEXT = 4096+HEADR; 112 if(INITDAT == -1) 113 INITDAT = 0; 114 break; 115 case Hlinux: /* elf64 executable */ 116 case Hfreebsd: /* freebsd */ 117 case Hnetbsd: /* netbsd */ 118 case Hopenbsd: /* openbsd */ 119 case Hdragonfly: /* dragonfly */ 120 case Hsolaris: /* solaris */ 121 elfinit(); 122 HEADR = ELFRESERVE; 123 if(INITTEXT == -1) 124 INITTEXT = (1<<22)+HEADR; 125 if(INITDAT == -1) 126 INITDAT = 0; 127 if(INITRND == -1) 128 INITRND = 4096; 129 break; 130 case Hnacl: 131 elfinit(); 132 debug['w']++; // disable dwarf, which gets confused and is useless anyway 133 HEADR = 0x10000; 134 funcalign = 32; 135 if(INITTEXT == -1) 136 INITTEXT = 0x20000; 137 if(INITDAT == -1) 138 INITDAT = 0; 139 if(INITRND == -1) 140 INITRND = 0x10000; 141 break; 142 case Hwindows: /* PE executable */ 143 peinit(); 144 HEADR = PEFILEHEADR; 145 if(INITTEXT == -1) 146 INITTEXT = PEBASE+PESECTHEADR; 147 if(INITDAT == -1) 148 INITDAT = 0; 149 if(INITRND == -1) 150 INITRND = PESECTALIGN; 151 break; 152 } 153 154 if(INITDAT != 0 && INITRND != 0) 155 print("warning: -D0x%llux is ignored because of -R0x%ux\n", 156 INITDAT, INITRND); 157 }