Windows Tools Flashcards
Build app.cpp at the command-line with the debug runtime DLL, exception handling, and a PDB.
cl.exe /MDd /EHsc /Zi app.cpp
Where is the vcruntime and crt source located after installing VS?
%VSINSTALLDIR%\VC\Tools\MSVC\14.16.26926\crt\src
Where are the Windows headers files installed to?
“%ProgramFiles(x86)%\Windows Kits\10\Include". This will have subfolders for “ucrt” (Universal C run-time), “um” (user mode), “winrt”, and “shared” (between user and kernel mode).
How do you include a symbol that is not referenced/exported into a binary (e.g. DLL) from a lib file?
In MSVC, “__pragma(comment (linker, “/export:” #symbol)”, in GCC, “gcc -u symbol”. Note: Or “/include”?
How can you specify to use or not use intrinsics?
Use #pragma intrinsic(intrinsic-function-name-list). The pragma can be used to specify a single intrinsic or multiple intrinsics separated by commas. Or use the /Oi (Generate Intrinsic Functions) compiler option, which makes all intrinsics on a given platform available. Under /Oi, use #pragma function(intrinsic-function-name-list) to force a function call to be used instead of an intrinsic. A header file, , is available that declares prototypes for the common intrinsic functions.
What type of .lib files does LINK accept?
LINK accepts COFF standard libraries and COFF import libraries, both of which usually have the extension .lib. Standard libraries contain objects and are created by the LIB tool. Import libraries contain information about exports in other programs and are created either by LINK when it builds a program that contains exports or by the LIB tool.
What is the output of the compiler before linking? What do these files consist of?
.obj files (known as “compilation units”), which are COFF files.
What is the “.bss”, “.data”, and “.rdata” sections in a COFF file?
Uninitializerd and initialized data, and read-only data. e.g. “int i;”, “int x = 10;”, and “const int z = -1;” at global scope respectively. The “.bss” section is often merged into the “.data” section.
What do the “.drectve” sections contain?
There are typically only in .obj files and are “directives” given to the linker (e.g. “/DEFAULTLIB:LIBCMTD”, or “-export:_ExportMe” if “__declspec(dllexport) ExportMe” was encountered).
What is the “.reloc” section for?
The .reloc section in an executable is basically a series of addresses in the executable where the difference between the default and actual load address needs to be accounted for. By default, the linker creates the executable so that the .reloc section isn’t needed by the Win32 loader. However, when the Win32 loader needs to load an executable somewhere other than its preferred load address, the .reloc section allows all the direct references to code and data to be updated.
What is the “.CRT” section for?
Tables of initialization and shutdown pointers used by the C runtime library.
What are the “.idata” and .edata” sections for?
“.idata” is the import table (i.e. symbols to use from other binaries). “.edata” is the export table (i.e. symbols exported from this binary).
What is a “REL32” fixup?
This fixup record says that the linker needs to calculate the relative offset to function Foo (defined outside the current compilation unit), and write that value to the given offset. Since this fixup record is only needed by the linker prior to creating the executable, it’s only in the .obj file, and doesn’t appear in the executable.
What is an “indirect reference” when a linker is using a .lib file?
Indirect means an OBJ included contains references to symbols in yet another OBJ file in the library. This second OBJ may in turn reference symbols in a third OBJ file in the library. One of the linker’s jobs is to track down and include every OBJ that has a referenced symbol.
What is the “.pdata” section?
Table-based exception handling requires a table entry for all functions that allocate stack space or call another function. These entries are sorted, and put in the .pdata section of a PE32+ image.
How can you view the undecorated name?
Use “dumpbin /symbols file.obj”. Generate the assembly with the “/FAs” compiler switch and see the “PUBLIC ; “ lines.
How do you build x64 versions of binaries with the command line tools?
Open the x64 Native Tools command prompt.
How do you create a .map file, and what is it?
Use the switch /Fm. A MAP file lists the public symbols that were included in the executable.
What is RVA?
Relative virtual address. In an image file, the address of an item after it is loaded into memory, with the base address of the image file subtracted from it. The RVA of an item almost always differs from its position within the file on disk (file pointer)