PE format allows to have variable length of Data Directories in PE Optional
Header. The exact number of Data Directories is stored in NumberOfRvaAndSizes
field. Size of the optional header depends on the number of Data Directories.
Constants IMAGE_SIZEOF_NT_OPTIONAL32_HEADER and IMAGE_SIZEOF_NT_OPTIONAL64_HEADER
are for PE images with all 16 Data Directories. And so cannot be used for
checking validity of SizeOfOptionalHeader.
Older PE linkers were generating PE binaries with less number of Data
Directories than 16 if trailing entries were empty. And gendef cannot
recognize such PE binaries.
Relax check for PE SizeOfOptionalHeader field. Allow any number of Data
Directories in PE Optional Header, including zero.
At the same time add checks for NumberOfRvaAndSizes member before
dereferencing DataDirectory[] array, which ensures that the entry is present.
Signed-off-by: Martin Storsjö <martin@martin.st>
When using GNU ld or GNU dlltool, it is needed to mark ordinal-only export
with NONAME keyword. Otherwise the import library would use export by name,
instead of by ordinal.
Signed-off-by: Martin Storsjö <martin@martin.st>
This code block detected that the return value is from other library
function. It does not mean that function forwards to another one.
For example lot of times gendef detected that the call is GetLastError()
from kernel32.dll. But it does not mean that the function was forwarded to
GetLastError(). It just means that one of the code branch was propagating
return value from GetLastError().
Signed-off-by: Martin Storsjö <martin@martin.st>
gendef by default always scans current directory for other hint .def files
which are later parsed. This default behavior is sometimes problematic, so
add an option --no-include-current-dir which disables scanning of the
current directory for other hint .def files.
Signed-off-by: Martin Storsjö <martin@martin.st>
Decorated I386 fastcall functions have symbols with "@NAME@SIZE" pattern.
Normally function symbols from libraries are exported undecorated, symbol
name matches the function name. But some libraries export I386 fastcall
functions with decorated symbol names.
For example msvcr80.dll library exports symbol "@_calloc_crt@8" for which
gendef without this change generates line "@_calloc_crt@8@8", which cannot
be easily used by applications. With this change it generates line
"@_calloc_crt@8 == @_calloc_crt@8" which allows applications to call
fastcall function _calloc_crt(void *ptr, size_t size).
Signed-off-by: Martin Storsjö <martin@martin.st>
Decorated I386 stdcall functions have symbols with "_NAME@SIZE" pattern.
Normally function symbols from libraries are exported undecorated, symbol
name matches the function name. But some libraries export I386 stdcall
functions with decorated symbol names.
For example msvcrt20.dll library exports symbol "__seh_longjmp_unwind@4"
and gendef without this change generated line "__seh_longjmp_unwind@4@4",
which cannot be easily used by applications. With this change it generates
line "_seh_longjmp_unwind@4 == __seh_longjmp_unwind@4" which allows
applications to call stdcall function _seh_longjmp_unwind(void *jmp).
Signed-off-by: Martin Storsjö <martin@martin.st>
binutils (objdump) accepts PE binaries (EXE/DLL) with zero value in
OptionalHeader's Magic field. Do same in gendef. Such I386 DLL binaries are
distributed as part of the Win32s.
Signed-off-by: Martin Storsjö <martin@martin.st>
By hardcoding the use of -Werror, we risk that the build can break
on any newer (or older) toolchain which can give warnings for
unexpected issues.
Fixing such issues is of course desired, but we shouldn't be breaking
the build universally, unless the user explicitly has asked for
this behaviour.
Signed-off-by: Martin Storsjö <martin@martin.st>
This tool isn't evolving particularly much at the moment, so the
additional value of knowing when a particular version was built
doesn't give much extra value.
Normally, a stripped build of gendef (on Linux) produces a binary
with the exact same hash each time. Using __DATE__ breaks that
reproducibility, if rebuilt on different days. It is possible to
avoid the issue by setting SOURCE_DATE_EPOCH to a fixed value when
building, but in this case, I think the printed date doesn't add much
value, so we could simply remove it. Most other similar tools don't
contain such printouts.
Signed-off-by: Martin Storsjö <martin@martin.st>
This tool was meant as a standalone replacement for dlltool,
for generating import libraries, but it never got feature parity
(in particular, it lacked support for generating symbol aliases,
which are cruicial for the core mingw-w64-crt import libraries).
The same author later created llvm-dlltool which fulfilled the
niche which genlib initially was meant to handle, effectively
orphaning genlib.
The last update to the source is in 2015, and no known third party
build configurations actually use this tool. (Although some might
be building the tool even if it isn't used; such builds will need
to be updated though.)
Signed-off-by: Martin Storsjö <martin@martin.st>