aboutsummaryrefslogtreecommitdiff
path: root/i386-link.c
diff options
context:
space:
mode:
authorThomas Preud'homme <robotux@celest.fr>2016-12-10 17:22:08 +0000
committerThomas Preud'homme <robotux@celest.fr>2016-12-10 18:14:10 +0000
commitfe6453f8f08b5c21a339b3169a837772a9864d62 (patch)
tree8f8efde2a3e1c6e3c8f7099a4c22d47e0f98c3f3 /i386-link.c
parentd31226c8738d948e2bb4133b56597fff25169e43 (diff)
downloadtinycc-fe6453f8f08b5c21a339b3169a837772a9864d62.tar.gz
tinycc-fe6453f8f08b5c21a339b3169a837772a9864d62.tar.bz2
Use functions to get relocation info
MSVC does not support array designator so cannot compile source using relocs_info. This commit replace the relocs_info array into a set of functions, each returning the value given by a given field of the struct reloc_info.
Diffstat (limited to 'i386-link.c')
-rw-r--r--i386-link.c70
1 files changed, 57 insertions, 13 deletions
diff --git a/i386-link.c b/i386-link.c
index 59d6fa7..5a0511c 100644
--- a/i386-link.c
+++ b/i386-link.c
@@ -21,20 +21,64 @@
#include "tcc.h"
+/* Returns 1 for a code relocation, 0 for a data relocation. For unknown
+ relocations, returns -1. */
+int code_reloc (int reloc_type)
+{
+ switch (reloc_type) {
+ case R_386_16:
+ case R_386_32:
+ case R_386_GOTPC:
+ case R_386_GOTOFF:
+ case R_386_GOT32:
+ case R_386_GOT32X:
+ case R_386_GLOB_DAT:
+ case R_386_COPY:
+ return 0;
+
+ case R_386_PC16:
+ case R_386_PC32:
+ case R_386_PLT32:
+ case R_386_JMP_SLOT:
+ return 1;
+ }
+
+ tcc_error ("Unknown relocation type: %d", reloc_type);
+ return -1;
+}
+
+/* Returns an enumerator to describe wether and when the relocation needs a
+ GOT and/or PLT entry to be created. See tcc.h for a description of the
+ different values. */
+int gotplt_entry_type (int reloc_type)
+{
+ switch (reloc_type) {
+ case R_386_16:
+ case R_386_32:
+ case R_386_GLOB_DAT:
+ case R_386_JMP_SLOT:
+ case R_386_COPY:
+ return NO_GOTPLT_ENTRY;
+
+ case R_386_PC16:
+ case R_386_PC32:
+ return AUTO_GOTPLT_ENTRY;
+
+ case R_386_GOTPC:
+ case R_386_GOTOFF:
+ return BUILD_GOT_ONLY;
+
+ case R_386_GOT32:
+ case R_386_GOT32X:
+ case R_386_PLT32:
+ return ALWAYS_GOTPLT_ENTRY;
+ }
+
+ tcc_error ("Unknown relocation type: %d", reloc_type);
+ return -1;
+}
+
static ElfW_Rel *qrel; /* ptr to next reloc entry reused */
-ST_DATA struct reloc_info relocs_info[R_NUM] = {
- INIT_RELOC_INFO (R_386_32, 0, NO_GOTPLT_ENTRY)
- INIT_RELOC_INFO (R_386_PC32, 1, AUTO_GOTPLT_ENTRY)
- INIT_RELOC_INFO (R_386_PLT32, 1, ALWAYS_GOTPLT_ENTRY)
- INIT_RELOC_INFO (R_386_GLOB_DAT, 0, NO_GOTPLT_ENTRY)
- INIT_RELOC_INFO (R_386_JMP_SLOT, 1, NO_GOTPLT_ENTRY)
- INIT_RELOC_INFO (R_386_GOTPC, 0, BUILD_GOT_ONLY)
- INIT_RELOC_INFO (R_386_GOTOFF, 0, BUILD_GOT_ONLY)
- INIT_RELOC_INFO (R_386_GOT32, 0, ALWAYS_GOTPLT_ENTRY)
- INIT_RELOC_INFO (R_386_GOT32X, 0, ALWAYS_GOTPLT_ENTRY)
- INIT_RELOC_INFO (R_386_16, 0, NO_GOTPLT_ENTRY)
- INIT_RELOC_INFO (R_386_PC16, 1, AUTO_GOTPLT_ENTRY)
-};
void relocate_init(Section *sr)
{