libtcc: new LIBTCCAPI tcc_set_options(TCCState*, const char*str)

This replaces       -> use instead:
-----------------------------------
- tcc_set_linker    -> tcc_set_options(s, "-Wl,...");
- tcc_set_warning   -> tcc_set_options(s, "-W...");
- tcc_enable_debug  -> tcc_set_options(s, "-g");

parse_args is moved to libtcc.c (now tcc_parse_args).

Also some cleanups:
- reorder TCCState members
- add some comments here and there
- do not use argv's directly, make string copies
- use const char* in tcc_set_linker
- tccpe: use fd instead of fp

tested with -D MEM_DEBUG: 0 bytes left
This commit is contained in:
grischka
2013-02-12 19:13:28 +01:00
parent 829655949b
commit 05108a3b0a
12 changed files with 909 additions and 987 deletions

View File

@ -6,13 +6,11 @@
under MS-Windows. See tcc-doc.html to have all the features.
Installation from the binary ZIP package:
-----------------------------------------
Unzip the package to a directory of your choice.
Set the system PATH:
--------------------
To be able to invoke the compiler from everywhere on your computer by
@ -20,7 +18,6 @@
system PATH.
Examples:
---------
Open a console window (DOS box) and 'cd' to the examples directory.
@ -39,9 +36,23 @@
tiny_impdef dll.dll (optional)
tcc hello_dll.c dll.def
For the 'libtcc_test' example type
tcc examples/libtcc_test.c -I libtcc -L libtcc -ltcc
Using libtcc as JIT compiler in your program
--------------------------------------------
Check out the 'libtcc_test' example:
- Running it from source:
tcc -I libtcc libtcc/libtcc.def -run examples/libtcc_test.c
- Compiling with TCC:
tcc examples/libtcc_test.c -I libtcc libtcc/libtcc.def
- Compiling with MinGW:
gcc examples/libtcc_test.c -I libtcc libtcc.dll
- Compiling with MSVC:
lib /def:libtcc\libtcc.def /out:libtcc.lib
cl /MD examples/libtcc_test.c -I libtcc libtcc.lib
Import Definition Files:
@ -58,7 +69,6 @@
the TCC commandline to link a program that uses opengl32.dll.
Header Files:
-------------
The system header files (except _mingw.h) are from the MinGW
@ -71,7 +81,6 @@
into your "tcc/include/winapi" directory.
Resource Files:
---------------
TCC can link windows resources in coff format as generated by MinGW's
@ -81,7 +90,6 @@
tcc app.c appres.o -o app.exe
Tiny Libmaker:
--------------
The included tiny_libmaker tool by Timovj Lahde can be used as
@ -90,29 +98,26 @@
tiny_libmaker [rcs] library objectfiles ...
Compilation from source:
------------------------
* You can use the MinGW and MSYS tools available at
http://www.mingw.org
Untar the TCC archive and type in the MSYS shell:
Untar the TCC archive and type in the MSYS shell:
./configure
make
make install
./configure [--prefix installpath]
make
make install
The default install location is c:\Program Files\tcc
* Alternatively you can compile TCC with just GCC from MinGW using
win32\build-tcc.bat
To install, copy the entire contents of the win32 directory to
where you want.
build-tcc.bat (from the win32 directory)
To install, copy the entire contents of the win32 directory to
where you want.
Limitations:
@ -128,7 +133,6 @@
- Bounds checking (option -b) is not supported on 64-bit OS.
Documentation and License:
--------------------------
TCC is distributed under the GNU Lesser General Public License. (See
@ -139,7 +143,6 @@
http://fabrice.bellard.free.fr/tcc/
WinAPI Help and 3rd-party tools:
--------------------------------
The Windows API documentation (Win95) in a single .hlp file is
@ -150,5 +153,4 @@
"ResEd", available at the RadASM website.
--- grischka

View File

@ -25,9 +25,10 @@
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <stdio.h>
#include <io.h>
#include <malloc.h>
char *get_export_names(FILE *fp);
char *get_export_names(int fd);
#define tcc_free free
#define tcc_realloc realloc
@ -114,7 +115,7 @@ usage:
if (v)
printf("--> %s\n", file);
p = get_export_names(fp);
p = get_export_names(fileno(fp));
if (NULL == p) {
fprintf(stderr, "tiny_impdef: could not get exported function names.\n");
goto the_end;
@ -149,18 +150,18 @@ the_end:
return ret;
}
/* -------------------------------------------------------------- */
int read_mem(FILE *fp, unsigned offset, void *buffer, unsigned len)
int read_mem(int fd, unsigned offset, void *buffer, unsigned len)
{
fseek(fp, offset, 0);
return len == fread(buffer, 1, len, fp);
lseek(fd, offset, SEEK_SET);
return len == read(fd, buffer, len);
}
/* -------------------------------------------------------------- */
/* -------------------------------------------------------------- */
#endif
char *get_export_names(FILE *fp)
char *get_export_names(int fd)
{
int l, i, n, n0;
char *p;
@ -182,20 +183,20 @@ char *get_export_names(FILE *fp)
n = n0 = 0;
p = NULL;
if (!read_mem(fp, 0, &dh, sizeof dh))
if (!read_mem(fd, 0, &dh, sizeof dh))
goto the_end;
if (!read_mem(fp, dh.e_lfanew, &sig, sizeof sig))
if (!read_mem(fd, dh.e_lfanew, &sig, sizeof sig))
goto the_end;
if (sig != 0x00004550)
goto the_end;
pef_hdroffset = dh.e_lfanew + sizeof sig;
if (!read_mem(fp, pef_hdroffset, &ih, sizeof ih))
if (!read_mem(fd, pef_hdroffset, &ih, sizeof ih))
goto the_end;
if (MACHINE != ih.Machine)
goto the_end;
opt_hdroffset = pef_hdroffset + sizeof ih;
sec_hdroffset = opt_hdroffset + sizeof oh;
if (!read_mem(fp, opt_hdroffset, &oh, sizeof oh))
if (!read_mem(fd, opt_hdroffset, &oh, sizeof oh))
goto the_end;
if (IMAGE_DIRECTORY_ENTRY_EXPORT >= oh.NumberOfRvaAndSizes)
@ -204,7 +205,7 @@ char *get_export_names(FILE *fp)
addr = oh.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress;
//printf("addr: %08x\n", addr);
for (i = 0; i < ih.NumberOfSections; ++i) {
if (!read_mem(fp, sec_hdroffset + i * sizeof ish, &ish, sizeof ish))
if (!read_mem(fd, sec_hdroffset + i * sizeof ish, &ish, sizeof ish))
goto the_end;
//printf("vaddr: %08x\n", ish.VirtualAddress);
if (addr >= ish.VirtualAddress && addr < ish.VirtualAddress + ish.SizeOfRawData)
@ -214,18 +215,18 @@ char *get_export_names(FILE *fp)
found:
ref = ish.VirtualAddress - ish.PointerToRawData;
if (!read_mem(fp, addr - ref, &ied, sizeof ied))
if (!read_mem(fd, addr - ref, &ied, sizeof ied))
goto the_end;
namep = ied.AddressOfNames - ref;
for (i = 0; i < ied.NumberOfNames; ++i) {
if (!read_mem(fp, namep, &ptr, sizeof ptr))
if (!read_mem(fd, namep, &ptr, sizeof ptr))
goto the_end;
namep += sizeof ptr;
for (l = 0;;) {
if (n+1 >= n0)
p = tcc_realloc(p, n0 = n0 ? n0 * 2 : 256);
if (!read_mem(fp, ptr - ref + l, p + n, 1) || ++l >= 80) {
if (!read_mem(fd, ptr - ref + l, p + n, 1) || ++l >= 80) {
tcc_free(p), p = NULL;
goto the_end;
}

View File

@ -79,7 +79,7 @@ int main(int argc, char **argv)
ElfW(Sym) *sym;
int i, fsize, iarg;
char *buf, *shstr, *symtab = NULL, *strtab = NULL;
int symtabsize = 0, strtabsize = 0;
int symtabsize = 0;//, strtabsize = 0;
char *anames = NULL;
int *afpos = NULL;
int istrlen, strpos = 0, fpos = 0, funccnt = 0, funcmax, hofs;
@ -171,7 +171,7 @@ int main(int argc, char **argv)
if (!strcmp(shstr + shdr->sh_name, ".strtab"))
{
strtab = (char *)(buf + shdr->sh_offset);
strtabsize = shdr->sh_size;
//strtabsize = shdr->sh_size;
}
}
}