github.com/golang-haiku/go-1.4.3@v0.0.0-20190609233734-1f5ae41cc308/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 Hhaiku: 76 case Hlinux: 77 case Hnacl: 78 case Hnetbsd: 79 case Hopenbsd: 80 case Hsolaris: 81 break; 82 } 83 84 switch(HEADTYPE) { 85 default: 86 diag("unknown -H option"); 87 errorexit(); 88 case Hplan9: /* plan 9 */ 89 HEADR = 32L + 8L; 90 if(INITTEXT == -1) 91 INITTEXT = 0x200000+HEADR; 92 if(INITDAT == -1) 93 INITDAT = 0; 94 if(INITRND == -1) 95 INITRND = 0x200000; 96 break; 97 case Helf: /* elf32 executable */ 98 HEADR = rnd(52L+3*32L, 16); 99 if(INITTEXT == -1) 100 INITTEXT = 0x80110000L; 101 if(INITDAT == -1) 102 INITDAT = 0; 103 if(INITRND == -1) 104 INITRND = 4096; 105 break; 106 case Hdarwin: /* apple MACH */ 107 machoinit(); 108 HEADR = INITIAL_MACHO_HEADR; 109 if(INITRND == -1) 110 INITRND = 4096; 111 if(INITTEXT == -1) 112 INITTEXT = 4096+HEADR; 113 if(INITDAT == -1) 114 INITDAT = 0; 115 break; 116 case Hlinux: /* elf64 executable */ 117 case Hfreebsd: /* freebsd */ 118 case Hhaiku: /* haiku */ 119 case Hnetbsd: /* netbsd */ 120 case Hopenbsd: /* openbsd */ 121 case Hdragonfly: /* dragonfly */ 122 case Hsolaris: /* solaris */ 123 elfinit(); 124 HEADR = ELFRESERVE; 125 if(INITTEXT == -1) 126 INITTEXT = (1<<22)+HEADR; 127 if(INITDAT == -1) 128 INITDAT = 0; 129 if(INITRND == -1) 130 INITRND = 4096; 131 break; 132 case Hnacl: 133 elfinit(); 134 debug['w']++; // disable dwarf, which gets confused and is useless anyway 135 HEADR = 0x10000; 136 funcalign = 32; 137 if(INITTEXT == -1) 138 INITTEXT = 0x20000; 139 if(INITDAT == -1) 140 INITDAT = 0; 141 if(INITRND == -1) 142 INITRND = 0x10000; 143 break; 144 case Hwindows: /* PE executable */ 145 peinit(); 146 HEADR = PEFILEHEADR; 147 if(INITTEXT == -1) 148 INITTEXT = PEBASE+PESECTHEADR; 149 if(INITDAT == -1) 150 INITDAT = 0; 151 if(INITRND == -1) 152 INITRND = PESECTALIGN; 153 break; 154 } 155 156 if(INITDAT != 0 && INITRND != 0) 157 print("warning: -D0x%llux is ignored because of -R0x%ux\n", 158 INITDAT, INITRND); 159 }