Windows Tools Flashcards
(49 cards)
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)
What is a ‘section’ within a file?
The basic unit of code or data within a PE or COFF file. For example, all code in an object file can be combined within a single section or (depending on compiler behavior) each function can occupy its own section. With more sections, there is more file overhead, but the linker is able to link in code more selectively. A section is similar to a segment in Intel 8086 architecture. All the raw data in a section must be loaded contiguously
What is a .lib file?
A .LIB file is really just a series of contiguous archive members,(with two exceptions). Each archive member corresponds to a COFF format .OBJ file. The first two archive members in a COFF .LIB file are special. Instead of .OBJ files, they act as a table of contents to the other archive members (for instance, the symbol name_CreateProcessA@40 to the offset of the archive member containing the code or data associated with that symbol).
How are import library .lib files different from static libraries in .lib files?
The linker resolves calls to DLL functions the same way as it does for internal (static) functions. The only real difference is that when you call a DLL function, the .OBJ file in the import library provides data for the executable’s import table rather than code for the actual function.
What is central or local deployment of the CRT?
Deployment of the CRT DLLs into either \Windows\System32 or into the application folder, respectively.
What is the recommended approach for using the CRT?
Because central deployment (by using a redistributable package or merge modules) enables Windows Update to automatically update the Visual C++ libraries, central deployment is recommended (over local or static).