Refactor complete for i386 target.
[tinycc/k1w1.git] / tccelf.h
blob3ac19c476baeb0a84cb8e4dd3280f2fd09246a87
1 /*
2 * ELF file handling for TCC
3 *
4 * Copyright (c) 2001-2004 Fabrice Bellard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #ifndef __TCCELF_H__
21 #define __TCCELF_H__
23 #define ARMAG "!<arch>\012" /* For COFF and a.out archives */
24 #define ELF_PAGE_SIZE 0x1000
26 typedef struct {
27 unsigned int n_strx; /* index into string table of name */
28 unsigned char n_type; /* type of symbol */
29 unsigned char n_other; /* misc info (usually empty) */
30 unsigned short n_desc; /* description field */
31 unsigned int n_value; /* value of symbol */
32 } Stab_Sym;
34 Section *new_symtab(TCCState *s1,
35 const char *symtab_name, int sh_type, int sh_flags,
36 const char *strtab_name,
37 const char *hash_name, int hash_sh_flags);
38 /* add tcc runtime libraries */
39 void tcc_add_runtime(TCCState *s1);
40 /* relocate symbol table, resolve undefined symbols if do_resolve is
41 true and output error if undefined symbol. */
42 void relocate_syms(TCCState *s1, int do_resolve);
43 /* relocate common symbols in the .bss section */
44 void relocate_common_syms(void);
45 /* relocate a given section (CPU dependent) */
46 void relocate_section(TCCState *s1, Section *s);
47 /* add various standard linker symbols (must be done after the
48 sections are filled (for example after allocating common
49 symbols)) */
50 void tcc_add_linker_symbols(TCCState *s1);
51 /* build GOT and PLT entries */
52 void build_got_entries(TCCState *s1);
53 /* return elf symbol value or error */
54 void *tcc_get_symbol_err(TCCState *s, const char *name);
55 /* load an object file and merge it with current files */
56 int tcc_load_object_file(TCCState *s1,
57 int fd, unsigned long file_offset);
58 /* load a '.a' file */
59 int tcc_load_archive(TCCState *s1, int fd);
61 /* section generation */
62 void section_realloc(Section *sec, unsigned long new_size);
63 void *section_ptr_add(Section *sec, unsigned long size);
64 void put_extern_sym(Sym *sym, Section *section,
65 unsigned long value, unsigned long size);
66 void greloc(Section *s, Sym *sym, unsigned long addr, int type);
67 int put_elf_str(Section *s, const char *sym);
68 int put_elf_sym(Section *s,
69 unsigned long value, unsigned long size,
70 int info, int other, int shndx, const char *name);
71 int add_elf_sym(Section *s, uplong value, unsigned long size,
72 int info, int other, int sh_num, const char *name);
73 void put_elf_reloc(Section *symtab, Section *s, unsigned long offset,
74 int type, int symbol);
75 void put_stabs(const char *str, int type, int other, int desc,
76 unsigned long value);
77 void put_stabs_r(const char *str, int type, int other, int desc,
78 unsigned long value, Section *sec, int sym_index);
79 void put_stabn(int type, int other, int desc, int value);
80 void put_stabd(int type, int other, int desc);
81 void *load_data(int fd, unsigned long file_offset, unsigned long size);
83 #endif /* __TCCELF_H__ */