|
Boost : |
Subject: Re: [boost] Boost and (Microsoft's) _SECURE_SCL
From: Holger Grund (holger.grund_at_[hidden])
Date: 2010-11-06 10:23:31
>>> I've been testing this, and it works well for object files being
>>> linked into one application (and presumably for static libraries),
>>> but appears not to detect mismatches between an application and a
>>> DLL, which basically makes it next to useless... unless I'm missing
>>> something?
>
>> If you're using import libs, that *should* work.
>
> I'm using import libraries - my test project is attached - no errors are
generated even though they have hardcoded mismatched #pragma
detect_mismatch's.
That doesn't work across PE images out of the box -- and arguably it's not
necessarily a good idea to flag these mismatches as an error. So long as DLL
& EXE have an interface that doesn't rely on STL constructs, there's no
problem.
Effectively, the #pragma detect_mismatch causes the corresponding
/FAILIFMISMATCH linker option to be emitted in a .drectve section. When the
linker encounters an object file it will process the contents of .drectve
section as command line switches (there's some additional logic, some
switches don't work in directive sections, others including /FAILIFMISMATCH
only work in directive sections).
In your case, the object files with the directives do not contribute to the
same image. Hence link.exe won't complain.
If your interface relies on STL constructs, you could add an object file to
the import library, make sure it's linked in by the consuming side and so
trigger validation.
E.g.
Lib_interface.hpp:
// ...
#pragma comment( linker, "/INCLUDE:_dll_impl_interface_mismatch_check")
Then add an object file into your import lib (*not* the DLL) which has a
public symbol with that name. You can add to an import lib, with the lib
command.
E.g.:
extern "C" const char dll_impl_interface_mismatch_check=0; /* x86 is the
only platform to add a leading underscore for C linkage names */
cl /c /Zl foo.cpp
lib import.lib foo.obj
Now on the consuming side, when a compilation unit sees a comment linker
pragma it will emit the /INCLUDE switch in the object file's directive
section. The linker will then resolve the symbol by selecting the object
file from the hybrid import library. It will then process that object file's
directive section which includes the /FAILIFMISMATCH switch, which in turn
should trigger a linker error.
dumpbin /DIRECTIVES shows linker options embedded in an object file
dumpbin /LINKERMEMBER shows the archive symbol table of a .lib
dumpbin /ARCHIVEMEMBERS shows object files (including the special import
objects) in a .lib
-hg
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk