pike.git / NT / tools / pntld

version» Context lines:

pike.git/NT/tools/pntld:1:   #!/usr/local/bin/pike    - /* Partial linker for COFF files, written by Fredrik Hubinette 2000 */ + // Partial linker for COFF files, written by Fredrik Hubinette 2000 + // + // Things left to do: + // Merge sections + // Test if resulting files work with cl.exe + // Support line number information + // Support 64 bit architechtures      class Reloc   {    Symbol sym;    int loc;    int type;   };      class Section   {
pike.git/NT/tools/pntld:28:    Section section;    int type;    int cls;    array(Symbol) aux;   };         mapping(string:Symbol) global_symbols=([]);   array(Section) global_sections=({});   array(string) global_directives=({}); + array(string) libpath=({}); + array(string) libraries=({});      class Linker   {    string ret="";    string stringtable="";    string symboltable="";    string sectiondata="";    string sectiontable="";    int num_symbols;   
pike.git/NT/tools/pntld:630:   #ifdef DEBUG    write("Yes.\n");   #endif    }    dumpCOFF(pos+4);    return 1;    }       void dumpArchive(int pos)    { +  string name; +  int num; +  int longnames;    while(pos < strlen(data))    { -  string name=range(pos,16); +  num++;    int size = (int) range(pos+48,10); -  +  name=range(pos,16); +  if(name[0]=='/') +  { +  if(num == 3) +  { +  longnames=pos+60; +  } +  else if(longnames && sscanf(name,"/%d",int longnamenum)) +  { +  name=nulltermstring(longnames + longnamenum); +  } +  }else{ +  if(sscanf(reverse(name),"%*s/%s",name)) +  name=reverse(name); +  }   #ifdef DEBUG    write("\n");    write("# name: %s\n",name); -  write("# date: %s\n",ctime( (int) range(pos+16,12) ) ); +  write("# date: %s",ctime( (int) range(pos+16,12) ) );    write("# uid : %s\n",range(pos+28,6));    write("# gid : %s\n",range(pos+34,6));    write("# mode: %s\n",range(pos+40,8));    write("# size: %s\n",range(pos+48,10));   #endif -  +     if(name[0]!='/') -  dumpfile(data, pos+60,0,name); -  +  { +  dumpfile(data, pos+60, 0, name); +  }    pos+=60;    pos+=(size+1)&~1;    }    }    -  +  void dumpImportLib() +  { +  string name= ( filename/"/" )[-1]; + #if 0 +  sscanf(range(0,20), +  "%-2c%-2c%-2c%-2c%-4c%-4c%-2c%-2c", +  int sig1, +  int sig2, +  int version, +  int machine, +  int timestamp, +  int size_of_data, +  int ordinal, +  int type); +  write("Sig1 : %x\n",sig1); +  write("Sig2 : %x\n",sig2); +  write("version : %x\n",version); +  write("Machine : %x\n", machine); +  write("Time : %s",ctime(timestamp)); +  write("Ordinal : %x\n",ordinal); +  write("Type: : %x\n",type); +  write("Name : %s\n",nulltermstring(20)); +  +  write("Importing library: %O\n",name); + #endif +  +  global_directives|=({ "-LIB:"+name }); +  } +     void create(string d, void|int p, void|int len, void|string f)    {    base=p;    data=d;    filename=f;    if(!len) len=strlen(d)-base;       if(range(0,8) == "!<arch>\n")    {   #ifdef DEBUG    write("Archive!\n");   #endif    dumpArchive(8);    }else{ -  if(len >=0x40 && !dumpPE(i4(0x3c))) +  if(i2(0) == 0 && i2(2) == 0xffff)    { -  +  dumpImportLib(); +  }else{    dumpCOFF(0);    }    }    }   }      int main(int argc, array(string) argv)   { -  +  int err;    int strip=0;    string output="a.out";   // werror("%O\n",argv);    werror("Pike Win32 partial linker.\n" -  "$Id: pntld,v 1.1 2000/12/23 07:19:49 hubbe Exp $\n" +  "$Id: pntld,v 1.2 2000/12/27 07:55:09 hubbe Exp $\n"    "Written by Fredrik Hubinette 2000\n");       foreach(Getopt.find_all_options(argv,aggregate(    ({"output",Getopt.HAS_ARG,({"-o"})}),    ({"R",Getopt.HAS_ARG,({"-R"})}),    ({"L",Getopt.HAS_ARG,({"-L"})}),    ({"l",Getopt.HAS_ARG,({"-l"})}),    ({"S",Getopt.NO_ARG,({"-S"})}),    ({"ignore","Getopt.HAS_ARG",({"-r","-i","-s","-g","-B","-W"})}),    )),array opt)    {    switch(opt[0])    {    case "S": strip++; break;    -  case "R": +     case "L": -  +  libpath|=({opt[1]}); +  break; +  +  case "R":    global_directives|=({ "-?rpath:"+opt[1] });    break;       case "l":    switch(opt[1])    {    case "c": case "m": break;    default: -  /* FIXME: -  * search for *.lib files and link them 'statically' -  * if found. -  */ -  global_directives|=({ "-lib:"+opt[1] }); +  libraries|=({opt[1]});    }    break;       case "output":    output=opt[1];    break;    }    }    -  +  if(getenv("NTLD_LIBRARY_PATH")) +  libpath|=getenv("NTLD_LIBRARY_PATH")/":"; +  +  if(getenv("NTLD_RUN_PATH")) +  foreach(getenv("NTLD_RUN_PATH")/":",string p) +  global_directives|=({"-?rpath:"+p}); +  +  libpath|=({"."}); +  +  foreach(libraries, string lib) +  { +  int found; +  foreach(libpath, string path) +  { +  string filename=combine_path(path,lib+".lib"); + #ifdef DEBUG +  werror("Looking for %s\n",filename); + #endif +  if(string file=Stdio.read_file(filename)) +  { +  dumpfile(file, 0, 0, filename); +  found=1; +  break; +  } +  +  filename=combine_path(path,upper_case(lib+".lib")); + #ifdef DEBUG +  werror("Looking for %s\n",filename); + #endif +  if(string file=Stdio.read_file(filename)) +  { +  dumpfile(file, 0, 0, filename); +  found=1; +  break; +  } +  } +  if(!found) +  { +  werror("Failed to find library: %s\n",lib); +  err++; +  } +  } +     argv=Getopt.get_args(argv);       foreach(argv[1..],string file)    dumpfile(Stdio.read_file(file),0,0,file+":"+file);       if(strip)    {    global_sections=Array.filter(global_sections,    lambda(Section s)    {
pike.git/NT/tools/pntld:746:    {    Section s=Section();    s->name=".drectve";    s->data=global_directives * " ";    s->characteristics = CHR_LINK_INFO | CHR_LINK_REMOVE | CHR_LINK_ALIGN_1;    s->relocs=({});       global_sections= ({s}) + global_sections;    }    +  if(err) exit(err);    rm(output);    Stdio.write_file(output,    Linker()->out(global_sections,    values(global_symbols))); -  exit(0); +  exit(err);   }