History

Checkin tiny_libmaker (ar replacement) by Timovj Lahde

grischka committed 18 years ago

Commit 2eaa1101 parent 265dddb7 files · +393 −72Browse files

Unified · Split

7 files
  1. Makefile +6 −2
  2. configure +14 −1
  3. win32/build-tcc.bat +3 −6
  4. win32/include/_mingw.h +10 −10
  5. win32/readme.txt +41 −53
  6. win32/tools/tiny_impdef.c +0 −0
  7. win32/tools/tiny_libmaker.c +319 −0
Makefile+6−2
@@ -19,8 +19,10 @@ ifeq ($(GCC_MAJOR),2) · 18 unmodified lines
19CFLAGS+=-m386 -malign-functions=019CFLAGS+=-m386 -malign-functions=0
20else20else
21CFLAGS+=-march=i386 -falign-functions=0 -fno-strict-aliasing21CFLAGS+=-march=i386 -falign-functions=0 -fno-strict-aliasing
22ifneq ($(GCC_MAJOR),3)
22CFLAGS+=-Wno-pointer-sign -Wno-sign-compare23CFLAGS+=-Wno-pointer-sign -Wno-sign-compare
23endif24endif
25endif
24 26
25DISAS=objdump -d27DISAS=objdump -d
26INSTALL=install28INSTALL=install
@@ -30,7 +32,7 @@ PROGS=tcc$(EXESUF) · 3 unmodified lines
30ifdef CONFIG_CROSS32ifdef CONFIG_CROSS
31PROGS+=c67-tcc$(EXESUF) arm-tcc$(EXESUF)33PROGS+=c67-tcc$(EXESUF) arm-tcc$(EXESUF)
32endif34endif
33PROGS+=tiny_impdef$(EXESUF)35PROGS+=tiny_impdef$(EXESUF) tiny_libmaker$(EXESUF)
34else36else
35ifeq ($(ARCH),i386)37ifeq ($(ARCH),i386)
36PROGS=tcc$(EXESUF)38PROGS=tcc$(EXESUF)
@@ -168,7 +170,9 @@ i386-win32-tcc$(EXESUF): tcc.c i386-gen.c tccelf.c tccasm.c i386-asm.c tcctok.h · 131 unmodified lines
168 $(CC) $(CFLAGS) -DTCC_TARGET_PE -o $@ $< $(LIBS)170 $(CC) $(CFLAGS) -DTCC_TARGET_PE -o $@ $< $(LIBS)
169 171
170# windows utilities172# windows utilities
171tiny_impdef$(EXESUF): tiny_impdef.c173tiny_impdef$(EXESUF): win32/tools/tiny_impdef.c
174 $(CC) $(CFLAGS) -o $@ $< -lkernel32
175tiny_libmaker$(EXESUF): win32/tools/tiny_libmaker.c
172 $(CC) $(CFLAGS) -o $@ $< -lkernel32176 $(CC) $(CFLAGS) -o $@ $< -lkernel32
173 177
174# TinyCC runtime libraries178# TinyCC runtime libraries
configure+14−1
@@ -181,7 +181,20 @@ EOF · 180 unmodified lines
181 181
182gcc_major="2"182gcc_major="2"
183if $cc -o $TMPO $TMPC 2> /dev/null ; then183if $cc -o $TMPO $TMPC 2> /dev/null ; then
184 gcc_major="3"184 gcc_major="3"
185fi
186cat > $TMPC <<EOF
187int main(void) {
188#if __GNUC__ >= 4
189return 0;
190#else
191#error gcc < 4
192#endif
193}
194EOF
195
196if $cc -o $TMPO $TMPC 2> /dev/null ; then
197 gcc_major="4"
185fi198fi
186 199
187if test x"$1" = x"-h" -o x"$1" = x"--help" ; then200if test x"$1" = x"-h" -o x"$1" = x"--help" ; then
win32/build-tcc.bat+3−6
@@ -2,17 +2,14 @@ · 1 unmodified line
2@rem batch file to build tcc using gcc and ar from mingw2@rem batch file to build tcc using gcc and ar from mingw
3@rem ----------------------------------------------------3@rem ----------------------------------------------------
4:4:
5@if exist ..\config.h goto configready5@echo>..\config.h #define TCC_VERSION "0.9.24"
6:
7@echo>..\config.h #define TCC_VERSION "0.9.24pre"
8@echo>>..\config.h #define TCC_TARGET_PE 16@echo>>..\config.h #define TCC_TARGET_PE 1
9@echo>>..\config.h #define CONFIG_TCCDIR NULL7@echo>>..\config.h #define CONFIG_TCCDIR NULL
10:8:
11:configready
12:
13gcc -Os -fno-strict-aliasing ../tcc.c -o tcc.exe -s9gcc -Os -fno-strict-aliasing ../tcc.c -o tcc.exe -s
14gcc -Os -fno-strict-aliasing ../tcc.c -D LIBTCC -c -o libtcc.o10gcc -Os -fno-strict-aliasing ../tcc.c -D LIBTCC -c -o libtcc.o
15gcc -Os -fno-strict-aliasing ../tiny_impdef.c -o tiny_impdef.exe -s11gcc -Os tools/tiny_impdef.c -o tiny_impdef.exe -s
12gcc -Os tools/tiny_libmaker.c -o tiny_libmaker.exe -s
16mkdir libtcc13mkdir libtcc
17ar rcs libtcc/libtcc.a libtcc.o14ar rcs libtcc/libtcc.a libtcc.o
18del libtcc.o15del libtcc.o
win32/include/_mingw.h+10−10
@@ -23,22 +23,21 @@ · 22 unmodified lines
23#define __int64 long long23#define __int64 long long
24#define __int32 long24#define __int32 long
25#define __int16 short25#define __int16 short
26#define __int8 char26#define __int8 char
27#define __cdecl __attribute__((__cdecl__))27#define __cdecl __attribute__((__cdecl__))
28#define __stdcall __attribute__((__stdcall__))28#define __stdcall __attribute__((__stdcall__))
29#define __declspec(x) __attribute__((x))29#define __declspec(x) __attribute__((x))
30 30
31#define __MINGW32_VERSION 2.031#define __MINGW32_VERSION 2.0
32#define __MINGW32_MAJOR_VERSION 232#define __MINGW32_MAJOR_VERSION 2
33#define __MINGW32_MINOR_VERSION 033#define __MINGW32_MINOR_VERSION 0
34 34
35#define __MSVCRT__35#define __MSVCRT__ 1
36#define __MINGW_IMPORT extern36#define __MINGW_IMPORT extern
37#define _CRTIMP37#define _CRTIMP
38#define __CRT_INLINE extern __inline__38#define __CRT_INLINE extern __inline__
39 39
40#define _WIN3240#define WIN32 1
41#define WIN32
42 41
43#ifndef _WINT_T42#ifndef _WINT_T
44#define _WINT_T43#define _WINT_T
@@ -46,7 +45,8 @@ typedef unsigned int wint_t; · 1 unmodified line
46#endif45#endif
47 46
48/* for winapi */47/* for winapi */
49#define NONAMELESSUNION48#define _ANONYMOUS_UNION
49#define _ANONYMOUS_STRUCT
50#define DECLSPEC_NORETURN50#define DECLSPEC_NORETURN
51#define WIN32_LEAN_AND_MEAN51#define WIN32_LEAN_AND_MEAN
52#define DECLARE_STDCALL_P(type) __stdcall type52#define DECLARE_STDCALL_P(type) __stdcall type
win32/readme.txt+41−53
@@ -1,37 +1,34 @@
1 1
2 TinyCC-PE2 TinyCC
3 ---------3 ======
4
5 TinyCC (aka TCC) is a small but hyperfast C compiler,
6 written by Fabrice Bellard,
7
8 4
9 TinyCC-PE is the TinyCC compiler with an extension to5 This file contains some additional information for usage of TinyCC
10 write PE executables for MS-Windows.6 under MS-Windows:
11 7
12 8
13 Features:9 Overview:
14 ---------10 ---------
11 TinyCC (aka TCC) is a small but hyperfast C compiler, written by
12 Fabrice Bellard.
15 13
16 TinyCC-PE can produce console applications, native windows14 TinyCC for MS-Windows can produce console applications, native
17 GUI programs and DLL's.15 windows GUI programs and DLL's.
18 16
19 Most of the features pointed out by Fabrice Bellard for the17 The package with under 300kb includes a complete C-compiler with
20 original version are still valid, i.e:18 header files and basic system library support.
21 19
22 - SMALL! The package with ~400kb includes a complete C-compiler20 With the -run switch you can run C-sources without any linking
23 with header files for console and GUI applications.21 directly from the command line.
24 22
25 - With the -run switch you can run C-sources without any23 TinyCC can be used as dynamic code generator library in your own
26 linking directly from the command line.24 program.
27 25
28 - TCC can of course compile itself.26 TinyCC can of course compile itself.
29 27
30 28
31 Compilation: (omit that if you use the binary ZIP package)29 Compilation: (omit that if you use the binary ZIP package)
32 ------------30 ------------
33 31 You can use the MinGW and MSYS tools available at
34 You must use the MinGW and MSYS tools available at
35 http://www.mingw.org to compile TCC for Windows. Untar the TCC32 http://www.mingw.org to compile TCC for Windows. Untar the TCC
36 archive and type in the MSYS shell:33 archive and type in the MSYS shell:
37 34
@@ -48,13 +45,14 @@ · 10 unmodified lines
48 45
49 Installation: (from the binary ZIP package)46 Installation: (from the binary ZIP package)
50 -------------47 -------------
51
52 Just unzip the package to a directory anywhere on your computer.48 Just unzip the package to a directory anywhere on your computer.
49
50 The binary package does not include libtcc. If you want tcc as
51 dynamic code generator, please use the source code distribution.
53 52
54 53
55 Examples:54 Examples:
56 ---------55 ---------
57
58 For the 'Fibonacci' console example type from the command line:56 For the 'Fibonacci' console example type from the command line:
59 57
60 tcc examples\fib.c58 tcc examples\fib.c
@@ -69,25 +67,22 @@ · 8 unmodified lines
69 tcc examples\hello_dll.c examples\dll.def67 tcc examples\hello_dll.c examples\dll.def
70 68
71 69
72 Import Definitions:70 Import Definition Files:
73 -------------------71 ------------------------
74 72 To link with Windows system DLLs, TinyCC uses import definition
75 TinyCC-PE searches and reads import definition files similar73 files (.def) instead of libraries.
76 to libraries.
77 74
78 The included 'tiny_impdef' program may be used to make .def files75 The included 'tiny_impdef' program may be used to make additional
79 for any DLL, e.g for an 'opengl32.def':76 .def files for any DLL. For example:
80 77
81 tiny_impdef.exe opengl32.dll78 tiny_impdef.exe opengl32.dll
82 79
83 or to the same effect:80 To use it, put the opengl32.def file into the tcc/lib directory,
84 81 and specify -lopengl32 at the tcc commandline.
85 tcc -run tiny_impdef.c opengl32.dll
86 82
87 83
88 Resource Files:84 Resource Files:
89 ---------------85 ---------------
90
91 TinyCC-PE can now link windows resources in coff format as generated86 TinyCC-PE can now link windows resources in coff format as generated
92 by MINGW's windres.exe. For example:87 by MINGW's windres.exe. For example:
93 88
@@ -95,32 +90,25 @@ · 1 unmodified line
95 tcc app.c appres.o -o app.exe90 tcc app.c appres.o -o app.exe
96 91
97 92
98 Header Files:93 Tiny Libmaker:
99 -------------94 --------------
100 95 The included tiny_libmaker tool by Timovj Lahde can be used as
101 The system header files, except '_mingw.h', are from the96 'ar' replacement to make a library from several object files.
102 3.7 mingw distribution. See also: http://www.mingw.org/
103
104
105 Compile TCC:
106 ------------
107 97
108 With TCC itself just say:
109 98
110 tcc src\tcc.c -o tcc.new.exe99 Header Files:
111 100 -------------
112 Other compilers like mingw-gcc or msvc work as well.101 The system header files (except _mingw.h) are from the mingw
113 To make libtcc1.a, you need 'ar' from the mingw binutils.102 distribution (http://www.mingw.org/).
114 103
115 104
116 Documentation and License:105 Documentation and License:
117 --------------------------106 --------------------------
118
119 TCC is distributed under the GNU Lesser General Public License107 TCC is distributed under the GNU Lesser General Public License
120 (see COPYING file).108 (see COPYING file).
121 109
122 Please read the original tcc-doc.html to have all the features110 Please read tcc-doc.html to have all the features of TCC. Also
123 of TCC. Also visit: http://fabrice.bellard.free.fr/tcc/111 visit: http://fabrice.bellard.free.fr/tcc/
124 112
125 --113
126 grischka@users.sourceforge.net114 -- grischka@users.sourceforge.net
win32/tools/tiny_impdef.crenamed from tiny_impdef.c+0−0

File renamed without changes.

win32/tools/tiny_libmaker.c+319−0
@@ -0,0 +1,319 @@
1/*
2 * This program is for making libtcc1.a without ar
3 * tiny_libmaker - tiny elf lib maker
4 * usage: tiny_libmaker [lib] files...
5 * Copyright (c) 2007 Timppa
6 *
7 * This program is free software but WITHOUT ANY WARRANTY
8 */
9#include <stdio.h>
10#include <stdlib.h>
11#include <string.h>
12
13/* #include "ar-elf.h" */
14/* "ar-elf.h" */
15/* ELF_v1.2.pdf */
16typedef unsigned short int Elf32_Half;
17typedef int Elf32_Sword;
18typedef unsigned int Elf32_Word;
19typedef unsigned int Elf32_Addr;
20typedef unsigned int Elf32_Off;
21typedef unsigned short int Elf32_Section;
22
23#define EI_NIDENT 16
24typedef struct {
25 unsigned char e_ident[EI_NIDENT];
26 Elf32_Half e_type;
27 Elf32_Half e_machine;
28 Elf32_Word e_version;
29 Elf32_Addr e_entry;
30 Elf32_Off e_phoff;
31 Elf32_Off e_shoff;
32 Elf32_Word e_flags;
33 Elf32_Half e_ehsize;
34 Elf32_Half e_phentsize;
35 Elf32_Half e_phnum;
36 Elf32_Half e_shentsize;
37 Elf32_Half e_shnum;
38 Elf32_Half e_shstrndx;
39} Elf32_Ehdr;
40
41typedef struct {
42 Elf32_Word sh_name;
43 Elf32_Word sh_type;
44 Elf32_Word sh_flags;
45 Elf32_Addr sh_addr;
46 Elf32_Off sh_offset;
47 Elf32_Word sh_size;
48 Elf32_Word sh_link;
49 Elf32_Word sh_info;
50 Elf32_Word sh_addralign;
51 Elf32_Word sh_entsize;
52} Elf32_Shdr;
53
54#define SHT_NULL 0
55#define SHT_PROGBITS 1
56#define SHT_SYMTAB 2
57#define SHT_STRTAB 3
58#define SHT_RELA 4
59#define SHT_HASH 5
60#define SHT_DYNAMIC 6
61#define SHT_NOTE 7
62#define SHT_NOBITS 8
63#define SHT_REL 9
64#define SHT_SHLIB 10
65#define SHT_DYNSYM 11
66
67typedef struct {
68 Elf32_Word st_name;
69 Elf32_Addr st_value;
70 Elf32_Word st_size;
71 unsigned char st_info;
72 unsigned char st_other;
73 Elf32_Half st_shndx;
74} Elf32_Sym;
75
76#define ELF32_ST_BIND(i) ((i)>>4)
77#define ELF32_ST_TYPE(i) ((i)&0xf)
78#define ELF32_ST_INFO(b,t) (((b)<<4)+((t)&0xf))
79
80#define STT_NOTYPE 0
81#define STT_OBJECT 1
82#define STT_FUNC 2
83#define STT_SECTION 3
84#define STT_FILE 4
85#define STT_LOPROC 13
86#define STT_HIPROC 15
87
88#define STB_LOCAL 0
89#define STB_GLOBAL 1
90#define STB_WEAK 2
91#define STB_LOPROC 13
92#define STB_HIPROC 15
93
94typedef struct {
95 Elf32_Word p_type;
96 Elf32_Off p_offset;
97 Elf32_Addr p_vaddr;
98 Elf32_Addr p_paddr;
99 Elf32_Word p_filesz;
100 Elf32_Word p_memsz;
101 Elf32_Word p_flags;
102 Elf32_Word p_align;
103} Elf32_Phdr;
104/* "ar-elf.h" ends */
105
106#define ARMAG "!<arch>\n"
107#define ARFMAG "`\n"
108
109typedef struct ArHdr {
110 char ar_name[16];
111 char ar_date[12];
112 char ar_uid[6];
113 char ar_gid[6];
114 char ar_mode[8];
115 char ar_size[10];
116 char ar_fmag[2];
117} ArHdr;
118
119
120unsigned long le2belong(unsigned long ul) {
121 return ((ul & 0xFF0000)>>8)+((ul & 0xFF000000)>>24) +
122 ((ul & 0xFF)<<24)+((ul & 0xFF00)<<8);
123}
124
125ArHdr arhdr = {
126 "/ ",
127 " ",
128 "0 ",
129 "0 ",
130 "0 ",
131 " ",
132 ARFMAG
133 };
134
135ArHdr arhdro = {
136 " ",
137 " ",
138 "0 ",
139 "0 ",
140 "0 ",
141 " ",
142 ARFMAG
143 };
144
145int main(int argc, char **argv)
146{
147 FILE *fi, *fh, *fo;
148 Elf32_Ehdr *ehdr;
149 Elf32_Shdr *shdr;
150 Elf32_Sym *sym;
151 int i, fsize, iarg;
152 char *buf, *shstr, *symtab = NULL, *strtab = NULL;
153 int symtabsize = 0, strtabsize = 0;
154 char *anames = NULL;
155 int *afpos = NULL;
156 int istrlen, strpos = 0, fpos = 0, funccnt = 0, funcmax, hofs;
157 char afile[260], tfile[260], stmp[20];
158
159
160 strcpy(afile, "ar_test.a");
161 iarg = 1;
162
163 if (argc < 2)
164 {
165 printf("usage: tiny_libmaker [lib] file...\n");
166 return 1;
167 }
168 for (i=1; i<argc; i++) {
169 istrlen = strlen(argv[i]);
170 if (argv[i][istrlen-2] == '.') {
171 if(argv[i][istrlen-1] == 'a')
172 strcpy(afile, argv[i]);
173 else if(argv[i][istrlen-1] == 'o') {
174 iarg = i;
175 break;
176 }
177 }
178 }
179
180 //tfile[0] = '.'; tfile[1] = '/';
181 //if (tmpnam(&tfile[2])) {
182 strcpy(tfile, "./XXXXXX");
183 if (mktemp(tfile))
184 {
185 if ((fo = fopen(tfile, "wb+")) == NULL)
186 {
187 fprintf(stderr, "Can't open file %s \n", tfile);
188 return 2;
189 }
190 }
191
192/*
193 if ((fo = tmpfile()) == NULL)
194 {
195 fprintf(stderr, "Can't open temporary file \n");
196 return 2;
197 }
198*/
199 if ((fh = fopen(afile, "wb")) == NULL)
200 {
201 fprintf(stderr, "Can't open file %s \n", afile);
202 remove(tfile);
203 return 2;
204 }
205
206 funcmax = 1000;
207 afpos = realloc(NULL, funcmax); // 250 func
208 memcpy(&arhdro.ar_mode, "100666", 6);
209
210 //iarg = 1;
211 while (iarg < argc)
212 {
213 if (!strcmp(argv[iarg], "rcs")) {
214 iarg++;
215 continue;
216 }
217 if ((fi = fopen(argv[iarg], "rb")) == NULL)
218 {
219 fprintf(stderr, "Can't open file %s \n", argv[iarg]);
220 remove(tfile);
221 return 2;
222 }
223 fseek(fi, 0, SEEK_END);
224 fsize = ftell(fi);
225 fseek(fi, 0, SEEK_SET);
226 buf = malloc(fsize + 1);
227 fread(buf, fsize, 1, fi);
228 fclose(fi);
229
230 printf("%s:\n", argv[iarg]);
231 // elf header
232 ehdr = (Elf32_Ehdr *)buf;
233 shdr = (Elf32_Shdr *) (buf + ehdr->e_shoff + ehdr->e_shstrndx * ehdr->e_shentsize);
234 shstr = (char *)(buf + shdr->sh_offset);
235 for (i = 0; i < ehdr->e_shnum; i++)
236 {
237 shdr = (Elf32_Shdr *) (buf + ehdr->e_shoff + i * ehdr->e_shentsize);
238 if (!shdr->sh_offset) continue;
239 if (shdr->sh_type == SHT_SYMTAB)
240 {
241 symtab = (char *)(buf + shdr->sh_offset);
242 symtabsize = shdr->sh_size;
243 }
244 if (shdr->sh_type == SHT_STRTAB)
245 {
246 if (!strcmp(shstr + shdr->sh_name, ".strtab"))
247 {
248 strtab = (char *)(buf + shdr->sh_offset);
249 strtabsize = shdr->sh_size;
250 }
251 }
252 }
253
254 if (symtab && symtabsize)
255 {
256 int nsym = symtabsize / sizeof(Elf32_Sym);
257 //printf("symtab: info size shndx name\n");
258 for (i = 1; i < nsym; i++)
259 {
260 sym = (Elf32_Sym *) (symtab + i * sizeof(Elf32_Sym));
261 if (sym->st_shndx && (sym->st_info == 0x11 || sym->st_info == 0x12)) {
262 //printf("symtab: %2Xh %4Xh %2Xh %s\n", sym->st_info, sym->st_size, sym->st_shndx, strtab + sym->st_name);
263 istrlen = strlen(strtab + sym->st_name)+1;
264 anames = realloc(anames, strpos+istrlen);
265 strcpy(anames + strpos, strtab + sym->st_name);
266 strpos += istrlen;
267 if (funccnt >= funcmax) {
268 afpos = realloc(NULL, funcmax+1000); // 250 func more
269 funcmax += 1000;
270 }
271 afpos[++funccnt] = fpos;
272 }
273 }
274 }
275 memset(&arhdro.ar_name, ' ', sizeof(arhdr.ar_name));
276 strcpy(arhdro.ar_name, argv[iarg]);
277 arhdro.ar_name[strlen(argv[iarg])] = '/';
278 sprintf(stmp, "%-10d", fsize);
279 memcpy(&arhdro.ar_size, stmp, 10);
280 fwrite(&arhdro, sizeof(arhdro), 1, fo);
281 fwrite(buf, fsize, 1, fo);
282 free(buf);
283 iarg++;
284 fpos += (fsize + sizeof(arhdro));
285 }
286 hofs = 8 + sizeof(arhdr) + strpos + (funccnt+1) * sizeof(int);
287 if ((hofs & 1)) { // align
288 hofs++;
289 fpos = 1;
290 } else fpos = 0;
291 // write header
292 fwrite("!<arch>\n", 8, 1, fh);
293 sprintf(stmp, "%-10d", strpos + (funccnt+1) * sizeof(int));
294 memcpy(&arhdr.ar_size, stmp, 10);
295 fwrite(&arhdr, sizeof(arhdr), 1, fh);
296 afpos[0] = le2belong(funccnt);
297 for (i=1; i<=funccnt; i++) {
298 afpos[i] = le2belong(afpos[i] + hofs);
299 }
300 fwrite(afpos, (funccnt+1) * sizeof(int), 1, fh);
301 fwrite(anames, strpos, 1, fh);
302 if (fpos) fwrite("", 1, 1, fh);
303 // write objects
304 fseek(fo, 0, SEEK_END);
305 fsize = ftell(fo);
306 fseek(fo, 0, SEEK_SET);
307 buf = malloc(fsize + 1);
308 fread(buf, fsize, 1, fo);
309 fclose(fo);
310 fwrite(buf, fsize, 1, fh);
311 fclose(fh);
312 free(buf);
313 if (anames)
314 free(anames);
315 if (afpos)
316 free(afpos);
317 remove(tfile);
318 return 0;
319}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t