Browse Source

* fix for DLL relocation problems
* external bss vars had wrong stabs for pecoff
+ -WB11000000 to specify default image base, allows to
load several DLLs with debugging info included
(relocatable DLL are stripped because the relocation
of the .Stab section is misplaced by ldw)

pierre 26 years ago
parent
commit
96fdcfb1f2
7 changed files with 104 additions and 13 deletions
  1. 4 1
      compiler/README
  2. 12 1
      compiler/globals.pas
  3. 15 3
      compiler/link.pas
  4. 13 1
      compiler/og386cff.pas
  5. 28 4
      compiler/options.pas
  6. 22 1
      compiler/pmodules.pas
  7. 10 2
      compiler/systems.pas

+ 4 - 1
compiler/README

@@ -52,4 +52,7 @@ Changes in the syntax or semantic of FPC:
              exceptions and exceptions need the class OOP model
   18/05/99   The compiler will stop directly if there are errors in the
              commandline parameters           
-
+  16/08/99   DLL are relocatable by default (need to strip symbols)
+             -WN make non relocatable DLL (which can retain debug info)
+             for both type of DLL the prefered image base can be specified
+             with -WB1100000 for instance to get image base at $11000000.

+ 12 - 1
compiler/globals.pas

@@ -170,6 +170,7 @@ unit globals;
     const
        RelocSection : boolean = true;
        DLLsource : boolean = false;
+       DLLImageBase : pstring = nil;
 
        { should we allow non static members ? }
        allow_only_static : boolean = false;
@@ -1168,6 +1169,8 @@ unit globals;
    procedure DoneGlobals;
      begin
         initdefines.done;
+        if assigned(DLLImageBase) then
+          StringDispose(DLLImageBase);
      end;
 
    procedure InitGlobals;
@@ -1233,7 +1236,15 @@ begin
 end.
 {
   $Log$
-  Revision 1.18  1999-08-11 17:26:32  peter
+  Revision 1.19  1999-08-16 15:35:21  pierre
+    * fix for DLL relocation problems
+    * external bss vars had wrong stabs for pecoff
+    + -WB11000000 to specify default image base, allows to
+      load several DLLs with debugging info included
+      (relocatable DLL are stripped because the relocation
+       of the .Stab section is misplaced by ldw)
+
+  Revision 1.18  1999/08/11 17:26:32  peter
     * tlinker object is now inherited for win32 and dos
     * postprocessexecutable is now a method of tlinker
 

+ 15 - 3
compiler/link.pas

@@ -587,6 +587,9 @@ var
   success    : boolean;
   ii         : longint;
 begin
+  { can be changed after InitLinker
+    for DLLs due to relocation problems PM }
+  Strip:=(cs_link_strip in aktglobalswitches);
 {$ifdef linux}
   if LinkToC then
    begin
@@ -632,8 +635,9 @@ begin
       same memory pool. The heap grows upwards, the stack grows downwards.}
      Replace(s,'$DOSHEAPKB',tostr((stacksize+maxheapsize+1023) shr 10));
      if Strip and Target_Link.StripBind then
-                   Replace (S, '$STRIP', Target_Link.StripOpt) else
-                                                     Replace (S, '$STRIP', '');
+       Replace (S, '$STRIP', Target_Link.StripOpt)
+     else
+       Replace (S, '$STRIP', '');
      if utilsdirectory<>'' then
        begin
           bindbin:=Search(target_link.bindbin[ii]+source_os.exeext,
@@ -767,7 +771,15 @@ end;
 end.
 {
   $Log$
-  Revision 1.66  1999-08-11 17:26:34  peter
+  Revision 1.67  1999-08-16 15:35:23  pierre
+    * fix for DLL relocation problems
+    * external bss vars had wrong stabs for pecoff
+    + -WB11000000 to specify default image base, allows to
+      load several DLLs with debugging info included
+      (relocatable DLL are stripped because the relocation
+       of the .Stab section is misplaced by ldw)
+
+  Revision 1.66  1999/08/11 17:26:34  peter
     * tlinker object is now inherited for win32 and dos
     * postprocessexecutable is now a method of tlinker
 

+ 13 - 1
compiler/og386cff.pas

@@ -614,6 +614,10 @@ unit og386cff;
          s:=currsec
         else }
          s:=section;
+        { do not use the size stored in offset field
+         this is DJGPP specific ! PM }
+        if win32 then
+          offset:=0;
         { local var can be at offset -1 !! PM }
         if reloc then
          begin
@@ -960,7 +964,15 @@ unit og386cff;
 end.
 {
   $Log$
-  Revision 1.11  1999-08-11 17:17:38  peter
+  Revision 1.12  1999-08-16 15:35:25  pierre
+    * fix for DLL relocation problems
+    * external bss vars had wrong stabs for pecoff
+    + -WB11000000 to specify default image base, allows to
+      load several DLLs with debugging info included
+      (relocatable DLL are stripped because the relocation
+       of the .Stab section is misplaced by ldw)
+
+  Revision 1.11  1999/08/11 17:17:38  peter
     * fixed rva writting for section relocs
     * fixed section flags for edata and idata
 

+ 28 - 4
compiler/options.pas

@@ -663,12 +663,28 @@ begin
                      IllegalPara(opt);
               'W' : begin
                       for j:=1 to length(More) do
-                       case More[j]of
+                       case More[j] of
                         'B': {bind_win32_dll:=true}
-                             RelocSection:=true;
+                             begin
+                               {  -WB200000 means set prefered base address
+                                 to $200000, but does not change relocsection boolean
+                                 this way we can create both relocatble and
+                                 non relocatable DLL at a specific base address PM }
+                               if (length(More)>j) then
+                                 begin
+                                   if DLLImageBase=nil then
+                                     DLLImageBase:=StringDup(Copy(More,j+1,255));
+                                 end
+                               else
+                                 RelocSection:=true;
+                               break;
+                             end;
                         'C': apptype:=at_cui;
                         'G': apptype:=at_gui;
-                        'N': RelocSection:=false;
+                        'N': begin
+                               RelocSection:=false;
+                             end;
+                             
                         'R': RelocSection:=true;
                        else
                         IllegalPara(opt);
@@ -1163,7 +1179,15 @@ end;
 end.
 {
   $Log$
-  Revision 1.13  1999-08-11 17:26:35  peter
+  Revision 1.14  1999-08-16 15:35:26  pierre
+    * fix for DLL relocation problems
+    * external bss vars had wrong stabs for pecoff
+    + -WB11000000 to specify default image base, allows to
+      load several DLLs with debugging info included
+      (relocatable DLL are stripped because the relocation
+       of the .Stab section is misplaced by ldw)
+
+  Revision 1.13  1999/08/11 17:26:35  peter
     * tlinker object is now inherited for win32 and dos
     * postprocessexecutable is now a method of tlinker
 

+ 22 - 1
compiler/pmodules.pas

@@ -233,12 +233,19 @@ unit pmodules;
                     target_link.linkcmd:=target_link.linkcmd+' --base-file base.$$$';
                     target_link.bindcmd[1]:=target_link.bindcmd[1]+' --base-file base.$$$';
                   end;
+                 if assigned(DLLImageBase) then
+                   begin
+                     target_link.linkcmd:=target_link.linkcmd+' --image-base=0x'+DLLImageBase^;
+                     target_link.bindcmd[2]:=target_link.bindcmd[2]+' --image-base=0x'+DLLImageBase^;
+                   end;
                end;
               if apptype=at_gui then
                begin
                 target_link.linkcmd:='--subsystem windows '+target_link.linkcmd;
                 target_link.bindcmd[2]:='--subsystem windows '+target_link.bindcmd[2];
                end;
+              if (cs_link_strip in aktglobalswitches) then
+                target_link.bindcmd[2]:='-s '+target_link.bindcmd[2];
             end;
 {$endif i386}
 {$ifdef m68k}
@@ -1189,6 +1196,12 @@ unit pmodules;
          if islibrary then
            begin
               consume(_LIBRARY);
+              { relocation works only without stabs !! PM }
+              if RelocSection then
+                begin
+                  aktglobalswitches:=aktglobalswitches+[cs_link_strip];
+                  aktmoduleswitches:=aktmoduleswitches-[cs_debuginfo];
+                end;
               stringdispose(current_module^.modulename);
               current_module^.modulename:=stringdup(pattern);
               current_module^.islibrary:=true;
@@ -1356,7 +1369,15 @@ unit pmodules;
 end.
 {
   $Log$
-  Revision 1.141  1999-08-11 17:26:36  peter
+  Revision 1.142  1999-08-16 15:35:27  pierre
+    * fix for DLL relocation problems
+    * external bss vars had wrong stabs for pecoff
+    + -WB11000000 to specify default image base, allows to
+      load several DLLs with debugging info included
+      (relocatable DLL are stripped because the relocation
+       of the .Stab section is misplaced by ldw)
+
+  Revision 1.141  1999/08/11 17:26:36  peter
     * tlinker object is now inherited for win32 and dos
     * postprocessexecutable is now a method of tlinker
 

+ 10 - 2
compiler/systems.pas

@@ -895,7 +895,7 @@ implementation
             binders : 0;
             bindbin : ('dlltool','ldw');
             bindcmd : ('--as asw.exe --dllname $EXE --output-exp exp.$$$',
-                       '-s $OPT -o $EXE $RES exp.$$$');
+                       '$OPT -o $EXE $RES exp.$$$');
             stripopt   : '-s';
             stripbind  : false;
             libpathprefix : 'SEARCH_DIR(';
@@ -1734,7 +1734,15 @@ begin
 end.
 {
   $Log$
-  Revision 1.90  1999-08-04 13:03:11  jonas
+  Revision 1.91  1999-08-16 15:35:29  pierre
+    * fix for DLL relocation problems
+    * external bss vars had wrong stabs for pecoff
+    + -WB11000000 to specify default image base, allows to
+      load several DLLs with debugging info included
+      (relocatable DLL are stripped because the relocation
+       of the .Stab section is misplaced by ldw)
+
+  Revision 1.90  1999/08/04 13:03:11  jonas
     * all tokens now start with an underscore
     * PowerPC compiles!!