From: Robert Pengelly Date: Wed, 19 Aug 2026 11:37:26 +0000 (+0100) Subject: Removed C90 limitations and NO_LONG_LONG related stuff as even MinGW on Windows 2000... X-Git-Url: https://git.candlhat.org/?a=commitdiff_plain;h=0f64b977fb6192b07e7d133600bd1b718642f03c;p=slink.git Removed C90 limitations and NO_LONG_LONG related stuff as even MinGW on Windows 2000 works --- diff --git a/Makefile.unix b/Makefile.unix index 7a4c91c..a13768c 100644 --- a/Makefile.unix +++ b/Makefile.unix @@ -5,7 +5,7 @@ SRCDIR ?= $(CURDIR) VPATH := $(SRCDIR) CC := gcc -CFLAGS := -D_FILE_OFFSET_BITS=64 -O2 -Wall -Werror -Wextra -ansi -pedantic -std=c90 +CFLAGS := -D_FILE_OFFSET_BITS=64 -O2 -Wall -Werror -Wextra CSRC := aout.c axe.c coff.c dx.c elf.c elks.c hashtab.c ld.c lib.c link.c ll.c macho.c map.c mz.c omf.c pe.c report.c section.c symbol.c vector.c write7x.c diff --git a/axe.c b/axe.c index 5aff0a4..99d66f7 100644 --- a/axe.c +++ b/axe.c @@ -260,27 +260,12 @@ static unsigned char *write_relocs_for_section64 (unsigned char *pos, struct sec r_symbolnum = AXE_TEXT; } -#if ((ULONG_MAX >> 16) >> 16) == 0xffffffff - if ((part->reloc_arr[i].r_symbolnum >> 27) & 1) { - r_symbolnum |= (1LU << 59); - } - - integer_to_array (r_symbolnum | (size_log2 << 57), rel.r_symbolnum, 8, 0); -#elif defined (NO_LONG_LONG) - integer_to_array (r_symbolnum, rel.r_symbolnum, 4, 0); - - if ((part->reloc_arr[i].r_symbolnum >> 27) & 1) { - r_symbolnum = (1LU << 27); - } - - integer_to_array (r_symbolnum | (size_log2 << 25), rel.r_symbolnum + 4, 4, 0); -#else if ((part->reloc_arr[i].r_symbolnum >> 27) & 1) { r_symbolnum |= (1LLU << 59); } integer_to_array (r_symbolnum | (size_log2 << 57), rel.r_symbolnum, 8, 0); -#endif + memcpy (pos, &rel, sizeof (rel)); pos += sizeof (rel); diff --git a/elf.c b/elf.c index 760e80e..ef5ed1b 100644 --- a/elf.c +++ b/elf.c @@ -1,6 +1,7 @@ /****************************************************************************** * @file elf.c *****************************************************************************/ +#include #include #include #include @@ -10,7 +11,6 @@ #include "elf.h" #include "report.h" #include "section.h" -#include "stdint.h" #include "symbol.h" #define UNNAMED_SYMBOL_NAME "(unnamed)" @@ -84,29 +84,19 @@ static void translate_relocation (const char *filename, struct reloc_entry *relo } -#ifndef NO_LONG_LONG -# define ELF64_R_SYM(i) ((i) >> 32) -# define ELF64_R_TYPE(i) ((i) & 0xffffffff) -#endif +#define ELF64_R_SYM(i) ((i) >> 32) +#define ELF64_R_TYPE(i) ((i) & 0xffffffff) static void translate_relocation64_addend (const char *filename, struct reloc_entry *reloc, struct elf64_rela *input_reloc, struct section_part *part, int endianess) { uint64_t r_info, r_offset; uint32_t symbol_index, rel_type; -#if defined (NO_LONG_LONG) - r_info = array_to_integer (input_reloc->r_info + 4, 4, endianess); - r_offset = array_to_integer (input_reloc->r_offset, 4, endianess); - - rel_type = array_to_integer (input_reloc->r_info, 4, endianess); - symbol_index = r_info; -#else r_info = array_to_integer (input_reloc->r_info, 8, endianess); r_offset = array_to_integer (input_reloc->r_offset, 8, endianess); symbol_index = ELF64_R_SYM (r_info); rel_type = ELF64_R_TYPE (r_info); -#endif if (symbol_index >= part->of->symbol_cnt) { diff --git a/elf.h b/elf.h index e822019..e10a44b 100644 --- a/elf.h +++ b/elf.h @@ -217,7 +217,7 @@ void elf32_write (const char *filename); void read_elf64_object (const char *filename, unsigned char *data, unsigned long data_size, int endianess); void elf64_write (const char *filename); -#include "stdint.h" +#include uint64_t elf_get_first_section_rva (void); #endif /* _ELF_H */ diff --git a/inttypes.h b/inttypes.h deleted file mode 100644 index 2ff8fed..0000000 --- a/inttypes.h +++ /dev/null @@ -1,24 +0,0 @@ -/****************************************************************************** - * @file inttypes.h - *****************************************************************************/ -#include - -#if defined (NO_LONG_LONG) -# define I64_FMT "l" -#elif defined (_MSVC_) -# define I64_FMT "I64" -#elif defined (__PRI_64_LENGTH_MODIFIER__) /* Mac */ -# define I64_FMT __PRI_64_LENGTH_MODIFIER__ -#elif (defined (SIZEOF_LONG) && SIZEOF_LONG >= 8) || ((ULONG_MAX >> 16) >> 16) == 0xffffffff -# define I64_FMT "l" -#else -# define I64_FMT "ll" -#endif - -#define PRId64 I64_FMT"d" -#define PRIi64 I64_FMT"i" -#define PRIo64 I64_FMT"o" -#define PRIu64 I64_FMT"u" -#define PRIx64 I64_FMT"x" -#define PRIX64 I64_FMT"X" - diff --git a/ld.c b/ld.c index 827d513..cb87f8b 100644 --- a/ld.c +++ b/ld.c @@ -540,19 +540,12 @@ int main (int argc, char **argv) { } else if (state->format == LD_FORMAT_AMD64_ELF || state->format == LD_FORMAT_I386_ELF) { state->base_address = 0x0040000; -#if defined(NO_LONG_LONG) - } else if (state->format == LD_FORMAT_AMD64_MACHO || state->format == LD_FORMAT_AARCH64_MACHO) { - state->base_address = 0x10000000; - } else if (state->format == LD_FORMAT_AARCH64_ELF) { - state->base_address = 0x14000000; - } -#else } else if (state->format == LD_FORMAT_AMD64_MACHO || state->format == LD_FORMAT_AARCH64_MACHO) { state->base_address = 0x100000000; } else if (state->format == LD_FORMAT_AARCH64_ELF) { state->base_address = 0x140000000; } -#endif + } if (state->format == LD_FORMAT_I386_AOUT) { diff --git a/ld.h b/ld.h index e5f6f92..77a2c26 100644 --- a/ld.h +++ b/ld.h @@ -5,7 +5,7 @@ #define _LD_H #define FAKE_LD_FILENAME "autogenerated" -#include "stdint.h" +#include struct ld_state { diff --git a/lib.c b/lib.c index ddb33a0..3136f18 100644 --- a/lib.c +++ b/lib.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -15,7 +16,6 @@ #include "mz.h" #include "pe.h" #include "report.h" -#include "stdint.h" struct options_with_use { @@ -534,10 +534,6 @@ uint64_t array_to_integer (unsigned char *arr, int size, int big_endian) { uint64_t value = 0; int i; -#if defined (NO_LONG_LONG) && ((ULONG_MAX >> 16) >> 16) < 0xffffffff - if (size == 8) { size = 4; } -#endif - if (big_endian) { int j; @@ -560,10 +556,6 @@ uint64_t array_to_integer (unsigned char *arr, int size, int big_endian) { void integer_to_array (uint64_t value, unsigned char *dest, int size, int big_endian) { -#if defined (NO_LONG_LONG) && ((ULONG_MAX >> 16) >> 16) < 0xffffffff - if (size == 8) { size = 4; } -#endif - if (big_endian) { int i, j; diff --git a/lib.h b/lib.h index c32f6d0..bc8a34c 100644 --- a/lib.h +++ b/lib.h @@ -19,7 +19,7 @@ struct ld_option { #define LD_OPTION_NO_ARG 0 #define LD_OPTION_HAS_ARG 1 -#include "stdint.h" +#include uint64_t array_to_integer (unsigned char *arr, int size, int big_endian); void integer_to_array (uint64_t value, unsigned char *dest, int size, int big_endian); diff --git a/link.c b/link.c index a140702..7c48011 100644 --- a/link.c +++ b/link.c @@ -3,6 +3,7 @@ *****************************************************************************/ #include #include +#include #include #include @@ -14,7 +15,6 @@ #include "reloc.h" #include "report.h" #include "section.h" -#include "stdint.h" #include "symbol.h" static uint64_t generic_read (struct section_part *part, struct reloc_entry *rel) { diff --git a/macho.c b/macho.c index b020ad2..0a07954 100644 --- a/macho.c +++ b/macho.c @@ -1044,31 +1044,6 @@ static void calculate_chained_fixups (struct chained_fixup_starts *cfs, int doin uint64_t result = array_to_integer (p->part->content + p->reloc_entry->offset, 8, 0); result -= state->base_address; -#if defined (NO_LONG_LONG) && ((ULONG_MAX >> 16) >> 16) < 0xffffffff - - integer_to_array (result, p->part->content + p->reloc_entry->offset, 4, 0); - - if (p + 1 != part_rels + num_relocs) { - - uint64_t rva1, rva2; - - rva1 = p->part->rva + p->reloc_entry->offset; - rva2 = p[1].part->rva + p[1].reloc_entry->offset; - - if (FLOOR_TO (rva1, PAGE_SIZE) != FLOOR_TO (rva2, PAGE_SIZE)) { - - p++; - break; - - } - - result = (((rva2 - rva1) / 4) & 0xfff) << 19; - integer_to_array (result, p->part->content + p->reloc_entry->offset + 4, 4, 0); - - } - -#else - result &= 0xfffffffff; if (p + 1 != part_rels + num_relocs) { @@ -1092,8 +1067,6 @@ static void calculate_chained_fixups (struct chained_fixup_starts *cfs, int doin } integer_to_array (result, p->part->content + p->reloc_entry->offset, 8, 0); - -#endif } diff --git a/map.c b/map.c index f0ba5a1..ce723c3 100644 --- a/map.c +++ b/map.c @@ -1,13 +1,12 @@ /****************************************************************************** * @file map.c *****************************************************************************/ -#include "stdint.h" - +#include +#include #include #include #include -#include "inttypes.h" #include "ld.h" #include "report.h" #include "section.h" diff --git a/section.h b/section.h index e72e827..4a92e65 100644 --- a/section.h +++ b/section.h @@ -4,8 +4,9 @@ #ifndef _SECTION_H #define _SECTION_H +#include + #include "reloc.h" -#include "stdint.h" #include "symbol.h" struct object_file { diff --git a/stdint.h b/stdint.h deleted file mode 100644 index 164c733..0000000 --- a/stdint.h +++ /dev/null @@ -1,50 +0,0 @@ -/****************************************************************************** - * @file stdint.h - *****************************************************************************/ -#ifndef _STDINT_H_INCLUDED -#ifndef _STDINT_H -#ifndef _STDINT_H_ - -#define _STDINT_H_INCLUDED -#define _STDINT_H -#define _STDINT_H_ - -#include - -/* Add all data types (even though we don't use them) as the project seems to fail to build on some systems. */ -typedef signed char int8_t; -typedef unsigned char uint8_t; - -typedef signed short int16_t; -typedef unsigned short uint16_t; - -#if INT_MAX > 32767 -typedef signed int int32_t; -typedef unsigned int uint32_t; -#else -typedef signed long int32_t; -typedef unsigned long uint32_t; -#endif - -#ifndef _INT64_T -#define _INT64_T -#if defined (NO_LONG_LONG) || ((ULONG_MAX >> 16) >> 16) == 0xffffffff -typedef signed long int64_t; -#else -typedef signed long long int64_t; -#endif -#endif /* _INT64_T */ - -#ifndef _UINT64_T -#define _UINT64_T -#if defined (NO_LONG_LONG) || ((ULONG_MAX >> 16) >> 16) == 0xffffffff -typedef unsigned long uint64_t; -#else -typedef unsigned long long uint64_t; -#endif -#endif /* _UINT64_T */ - -#endif /* _STDINT_H_ */ -#endif /* _STDINT_H */ -#endif /* _STDINT_H_INCLUDED */ - diff --git a/symbol.h b/symbol.h index 6cc39c2..0823313 100644 --- a/symbol.h +++ b/symbol.h @@ -4,8 +4,8 @@ #ifndef _SYMBOL_H #define _SYMBOL_H +#include #include "section.h" -#include "stdint.h" struct symbol {