openexr-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Openexr-devel] buf + fix for CreateDLL tool on Windows


From: Ger Hobbelt
Subject: [Openexr-devel] buf + fix for CreateDLL tool on Windows
Date: Tue, 17 Jun 2008 09:06:56 +0200

Very nice idea, this CreateDLL, by the way. :-) (comes in handy for a
few other DLL/C++ issues here. Dang. Why didn't I think of this?)

Anyway, what happens is that CreateDLL scans the map file for exports,
object files and DLLs in that order.
By the time the code has arrived at the spot where it's looking for
the DLL dependencies to tell 'link.exe' which matching '.lib's to
load, the scan is prematurely aborted as the 'object file scan'
corrupted the mapfile in memory (stored in buf; 'lineend' is the
offending pointer though).

This happens, because where it says:

-                    *lineend = '\0';

to replace an EOL by a NUL sentinel for the next of work, the code
assumes this 'lineend' pointer does NOT change until this line:

-                    *lineend = '\n';

where the EOL is restored.

Alas, this assumption is not true, as there's this bit of code:

                             if (accept) {
                                 lineend = lineend - 6;  // point one
character before ".dll"
                                 while (!isWhitespace(*lineend))
                                 {
                                     --lineend;
                 ...........

whoops. lineend on the move, before we got at '*lineend = '\n';'


The two added '#if 0' sections are there because link.exe should be
fed _all_ DLLs and objects the previous link run (which produced the
map file) received, under all circumstances.
This is especially true when using CreateDLL for other projects than
just this one. ;-)


unified diff for this has been included below.
the variable 'le' is a stable (untouched) copy of 'lineend' so the
assumption holds in the fixed code.



Old & new code tested with MSVC2005SP1 (VC8) on XP (32-bit).


I hope this helps,

take care,

Ger



--- \\Debbie\ger\prj\1original\OpenEXR\src\IlmBase\vc\createDLL\createDLL.cpp   
2007-08-23
20:17:54.000000000 +-0200
+++ \\Debbie\ger\prj\3actual\OpenEXR\IlmBase\vc\createDLL\createDLL.cpp 
2008-06-17
08:39:48.000000000 +-0200
@@ -410,31 +411,35 @@
                 {
                     --lineend;
                 }
                 ++lineend;

                 if (lineend != 0) {
-                    *lineend = '\0';
+                                       char *le = lineend; // [i_a] copy 
pointer as it will change
before we write back the \n here!
+                    *le = '\0';

                     char* owner = strchr(end, ':');

                     // if there is no colon, it could be ours (if
there is a colon it definitely isn't)
                     if (owner != 0) {

                         // if the symbol came from an obj, it is an export
                         if (*(lineend-3) == 'd' && *(lineend-2) ==
'l' && *(lineend-1) == 'l') {

                             bool accept = true;
+
+#if 0
                             int filterNum = 0;

-                            while (accept && filterSymbols[filterNum] != 0) {
+                                                       while (accept && 
filterSymbols[filterNum] != 0) {
                                 if (0 != strstr(buf,
filterSymbols[filterNum])) {
                                     accept = false;
                                 }
                                 ++filterNum;
                             }
+#endif

                             if (accept) {
                                 lineend = lineend - 6;  // point one
character before ".dll"
                                 while (!isWhitespace(*lineend))
                                 {
                                     --lineend;
@@ -449,18 +454,17 @@
                                 {
                                     libs.insert(object);
                                 }
                             }
                         }
                     }
-                    *lineend = '\n';
+                    *le = '\n';
                 }
             }
             buf = end;
         }
-
     }
 }



 static void addLibsFromVector(set<string>& libs, vector<string>& morelibs)
@@ -522,30 +526,34 @@
                 {
                     --lineend;
                 }
                 ++lineend;

                 if (lineend != 0) {
-                    *lineend = '\0';
+                                       char *le = lineend; // [i_a] copy 
pointer as it will change
before we write back the \n here!
+                    *le = '\0';

                     char* owner = strchr(end, ':');

                     // if there is no colon, it could be ours (if
there is a colon it definitely isn't)
                     if (owner == 0) {

                         // if the symbol came from an obj, it is an export
                         if (*(lineend-3) == 'o' && *(lineend-2) ==
'b' && *(lineend-1) == 'j') {

                             bool accept = true;
-                            int filterNum = 0;
+
+#if 0
+                                                       int filterNum = 0;
                             while (accept && filterSymbols[filterNum] != 0) {
                                 if (0 != strstr(buf,
filterSymbols[filterNum])) {
                                     accept = false;
                                 }
                                 ++filterNum;
                             }
+#endif

                             if (accept) {
                                 lineend = lineend - 6;  // point one
character before ".obj"
                                 while (!isWhitespace(*lineend))
                                 {
                                     --lineend;
@@ -558,13 +566,13 @@
                                 {
                                     objs.insert(object);
                                 }
                             }
                         }
                     }
-                    *lineend = '\n';
+                    *le = '\n';
                 }
             }
             buf = end;
         }

     }



-- 
Met vriendelijke groeten / Best regards,

Ger Hobbelt

--------------------------------------------------
web: http://www.hobbelt.com/
 http://www.hebbut.net/
mail: address@hidden
mobile: +31-6-11 120 978
--------------------------------------------------




reply via email to

[Prev in Thread] Current Thread [Next in Thread]