mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-02-12 17:27:56 +00:00
If you build a static ELF executable in `ld -q` mode (which leaves rela sections inside the binary) then you can run it through the elf2pe.com program afterwards, which will turn it into a PE executable. We have a new trick for defining WIN32 DLL imports in C without any assembly code. This also achieves the optimally tiny and perfect PE binary structure. We need this because it isn't possible to have a GNU ld linker script generate a PE file where the virtual pointer and the file pointer can drift apart. This post-linker can do that. One cool benefit is we can now use a smaller 512-byte alignment in the file, and an even bigger 64kb alignment for the segment virtual addresses, and the executable ends up being smaller. Another program introduced by this change is pecheck.com which can do extensive linting of PE static executables to help explain why Windows won't load it.
96 lines
2.2 KiB
C
96 lines
2.2 KiB
C
#ifndef COSMOPOLITAN_LIBC_ELF_STRUCT_SYM_H_
|
|
#define COSMOPOLITAN_LIBC_ELF_STRUCT_SYM_H_
|
|
#include "libc/elf/scalar.h"
|
|
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
|
|
|
typedef struct Elf64_Sym {
|
|
|
|
/*
|
|
* Symbol name.
|
|
*
|
|
* This value is a byte offset into the `.strtab` section. If this
|
|
* value is zero, then the symbol has no name.
|
|
*/
|
|
Elf64_Word st_name;
|
|
|
|
/*
|
|
* Symbol type and binding.
|
|
*
|
|
* This value may be created using:
|
|
*
|
|
* sym.st_info = ELF64_ST_INFO(bind, type);
|
|
*
|
|
* This value may be read using:
|
|
*
|
|
* int bind = ELF64_ST_BIND(sym.st_info);
|
|
* int type = ELF64_ST_TYPE(sym.st_info);
|
|
*
|
|
* Where `bind` is typically:
|
|
*
|
|
* - `STB_LOCAL`
|
|
* - `STB_GLOBAL`
|
|
* - `STB_WEAK`
|
|
*
|
|
* Where `type` is typically:
|
|
*
|
|
* - `STT_NOTYPE`
|
|
* - `STT_OBJECT`
|
|
* - `STT_FUNC`
|
|
* - `STT_SECTION`
|
|
* - `STT_FILE`
|
|
* - `STT_COMMON`
|
|
* - `STT_TLS`
|
|
*/
|
|
uint8_t st_info;
|
|
|
|
/*
|
|
* Symbol visibility.
|
|
*
|
|
* This value should be accessed using:
|
|
*
|
|
* int visibility = ELF64_ST_VISIBILITY(sym.st_other);
|
|
*
|
|
* Where `visibility` is typically:
|
|
*
|
|
* - `STV_DEFAULT`
|
|
* - `STV_INTERNAL`
|
|
* - `STV_HIDDEN`
|
|
* - `STV_PROTECTED`
|
|
*/
|
|
uint8_t st_other;
|
|
|
|
/*
|
|
* Symbol section.
|
|
*
|
|
* If `st_shndx` is within `(SHN_UNDEF,SHN_LORESERVE)` then it holds
|
|
* an index into the section header table.
|
|
*
|
|
* Otherwise `st_shndx` is usually one of the following magic numbers:
|
|
*
|
|
* - `SHN_UNDEF` means symbol is undefined
|
|
* - `SHN_ABS` means symbol is a linker integer
|
|
* - `SHN_COMMON` means symbol is defined traditionally
|
|
*/
|
|
Elf64_Section st_shndx;
|
|
|
|
/*
|
|
* Symbol value.
|
|
*
|
|
* If `e_type` is `ET_REL` and `st_shndx` is `SHN_COMMON`, then
|
|
* `st_value` holds the required symbol alignment, or ≤ 1 if no
|
|
* alignment is required.
|
|
*
|
|
* If `e_type` is `ET_REL` and `st_shndx` is a section index, then
|
|
* `st_value` holds a byte offset into the section memory.
|
|
*
|
|
* If `e_type` isn't `ET_REL` then `st_value` holds a virtual address.
|
|
*/
|
|
Elf64_Addr st_value;
|
|
|
|
/* byte length optionally set by .size directive */
|
|
Elf64_Xword st_size;
|
|
|
|
} Elf64_Sym;
|
|
|
|
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
|
#endif /* COSMOPOLITAN_LIBC_ELF_STRUCT_SYM_H_ */
|