Format of the .crt section in a Portable Executable (PE) file? - portable-executable

A Windows exe file may contain a .crt section.
The Portable Executable (PE) data specification defines the format of many sections (.edata, .idata, .rsrc, .pdata, etc) but it does not define the format of the .crt section. Where can I find the specification of the format of the .crt section?

Related

Is there a way to create a resource-only DLL using mingw compiler tools?

It is possible with MSVC to create a so-called resource-only DLL which essentually is a DLL that contains no machine code, but only resources. Is there a way to create a DLL only resource file using mingw? (If not possible, is it possible using open source tools?)
I know you can use windres to compile rc files into .res files. But the resources are appended with the compiler. but what if I have nothing to compile?
windres documentation says you can compile resources to coff object format and link it:
The normal use is for you to write an rc file, use windres to convert it to a COFF object file, and then link the COFF file into your application.
If the input or output format is not specified, windres will guess based on the file name, or, for the input file, the file contents. A file with an extension of .rc will be treated as an rc file, a file with an extension of .res will be treated as a res file, and a file with an extension of .o or .exe will be treated as a coff file.
So, e.g. with my.rc:
1 BITMAP "Untitled.bmp"
You can build it into dll by invoking:
windres -i my.rc -o my.o
ld --dll -o my.dll my.o

How can I choose shared library I need when has 2 share libraries in the file?

There are two shared libraries that are the same name but different suffixes. eg. (A.dll and A.lib). Now when I use the command “make” to make C codes, the compiler chooses the A.lib as the default option. Then how can I choose the flexibly library I need? And the following code is the code of makefile.
CC = gcc
COSI_LIB = '/C/A'
OBJ_NAME = B.exe
SOURCE =  B.c
${OBJ_NAME}: ${SOURCE}
    #$(CC) -I${COSI_LIB} -L${COSI_LIB} -lA -o ${OBJ_NAME} ${SOURCE}
clean:
    #rm $(OBJ_NAME) -r -f
I need to know that When there are two same name files but different format (ex. One named abc.dll and another named abc.lib) and I input command ‘make’ on term, I wish that compiler select .dll file instead of .lib file.
First, the compiler doesn't care about any .lib or .dll files, only the linker does.
Second, on Windows, the linker never uses .dlls. It always uses .lib, and it is the .lib file which contains either .o files (which are linked directly into your binary), or "dll imports", which tell the linker to build "import tables" to be used at runtime to import the functions from a corresponding .dll.
That is (unlike on UNIX) you don't get to decide whether to link against .lib or .dll (you always link against .lib). Whoever built the .lib and the .dll decided which (if any) parts are to be linked in directly, and which are to be imported from the .dll.

Set autotools library filename and reference it later on

I'm using autotools to build a library which will later be loaded by another program. This library has to have a .so extension to it regardless of the platform I'm on (this is a requirement imposed by the program loading it), and I'd also like it to not have a version specifier. How can I set the output name of such a library?
This is what Makefile.am looks like
lib_LTLIBRARIES = mylib.la
mylib_la_SOURCES = mylib.c
mylib_la_CPPFLAGS = $(LTDLINCL)
mylib_la_CFLAGS = $(CFLAGS) $(LIBFFI_CFLAGS)
LDADD = $(LIBLTDL) -dlopen self
Reading through the libtool manpage, it seems I need to set -install_name, but I don't see it referenced in the generated Makefile anywhere.
I also need to be able to reference this library's output directory elsewhere in the Makefiles (for testing purposes), is there a variable containing its basename or full path?
How can I set the output name of such a library?
The output name of the library will be the name given in lib_LTLIBRARIES without the suffix .a. It will generate by default a shared library - .so. Thus, you do not need to specify anything else.
I also need to be able to reference this library's output directory elsewhere in the Makefiles (for testing purposes), is there a variable containing its basename or full path?
The variable $(libdir) or #libdir# in the Makefile will point to the full path of the library directory.

The -l option in GCC

I have just begun reading the book Advanced Programming in Unix Environment and try to compile the first example code, just the same as in this question.
Although the problem for the compilation is solved using the command,
gcc -o myls myls.c -I SCADDRESS/include/ -L SCADDRESS/lib/ -lapue
I looked it up in the GCC manual, but what does the GCC option -lxxx mean? Where xxx stands for the base name of a header file (in this case, it's apue.h). According to the manual, xxx should be some library files, either end with .so for shared object files, or with .a for static libraries.
This is documented in §2.13 "Options for Linking" in the GCC manual:
-llibrary
Search the library named library when linking.
It makes a difference where in the command you write this option; the
linker searches processes libraries and object files in the order they
are specified. Thus, `foo.o -lz bar.o' searches library `z'
after file `foo.o' but before `bar.o'. If `bar.o' refers
to functions in `z', those functions may not be loaded.
The linker searches a standard list of directories for the library,
which is actually a file named `liblibrary.a'. The linker then uses this file as if it had been specified precisely by name.
The directories searched include several standard system directories
plus any that you specify with `-L'.
Normally the files found this way are library files--archive files
whose members are object files. The linker handles an archive file by
scanning through it for members which define symbols that have so far
been referenced but not defined. But if the file that is found is an
ordinary object file, it is linked in the usual fashion. The only
difference between using an `-l' option and specifying a file name is that `-l' surrounds library with `lib' and `.a'
and searches several directories.
The -l option tells GCC to link in the specified library. In this case, the library is apue, and that it happens to line up with the name of a header file is just how the apue coders designed their project.
In reality, the -l option has nothing to do with header files. Like cas says in the comments, read the man page; it'll give you much more information.

How to determine is file a dll library using winapi

I need to find all *.exe and *.dll files in selected directory (with subdirectories). For determining *.exe I use GetBinaryType, but I can't to determine that current file is dll.
The part of code
if (GetBinaryType(wName, &binaryType) || /*condition: if wName is DLL*/) {
System::Diagnostics::Debug::WriteLine(fName);
}
Just read IMAGE_FILE_HEADER record of file. If Characteristics field contain IMAGE_FILE_DLL flag - you have dll.

Resources