1
0
mirror of https://git.FreeBSD.org/ports.git synced 2024-11-20 00:21:35 +00:00

Update files/README.tccelf files/patch-libtcc.c to reflect some

fixes i made recently.
Add files/patch-z1-preproc which implements -include, -M and some
related preprocessing macros to improve portability
Bump portrevision accordingly

Should close PR/141185
This commit is contained in:
Luigi Rizzo 2009-12-06 15:08:37 +00:00
parent 3a3b9b6e55
commit 17093cca0d
Notes: svn2git 2021-03-31 03:12:20 +00:00
svn path=/head/; revision=245285
4 changed files with 263 additions and 38 deletions

View File

@ -7,7 +7,7 @@
PORTNAME= tcc
PORTVERSION= 0.9.25
PORTREVISION= 1
PORTREVISION= 2
CATEGORIES= lang
MASTER_SITES= ${MASTER_SITE_SAVANNAH}
MASTER_SITE_SUBDIR= tinycc

View File

@ -1,17 +1,11 @@
The patches in this directory include some updates to tcc 0.9.25.
Some of them have been committed in the main tcc repository so
we will not need them in future updates.
I think i have managed to solve the problem and produce
almost valid elf files on FreeBSD. The two patches attached
should go in ports/tcc/files (patch-libtcc.c replaces
the existing one with the same name) and bumping PORTREVISION
should complete the job. I can do the commit myself if the
maintainer has no time.
In particular:
The patches address a few problems (trying to explain to the
best of my knowledge; i am not very familiar with ELF and
the FreeBSD ELF conventions):
1. ELF file format
tcc produces an ELF executable which is good for linux but
1. ELF file format (merged upstream)
tcc 0.9.25 produces an ELF executable which is good for linux but
not for FreeBSD. It misses the PHDR section which is almost
mandatory for shared executables, puts in the .dynsym section
some relocation info that FreeBSD expects to be in .got,
@ -23,21 +17,23 @@ the FreeBSD ELF conventions):
loader through an environment variable (this is important to
debug tcc).
2. predefined macros
The resulting elf file is still not 100% correct -- if you strip it,
the program will not run (presumably there is some dangling reference).
Other than that, program do seem to run correctly.
2. predefined macros (partially merged upstream)
patch-libtcc.c adds/fixes some predefined macros when compiling
on FreeBSD: these are __FreeBSD__ and the usual set of
__i386__ and __unix__ variants.
It also sets __INTEL_COMPILER so we can grab the __aligned
macro from cdefs.h , otherwise many programs would fail
It also #defines __builtin_inline(x,y), __PRETTY_FUNCTION__,
__CC_SUPPORTS___INLINE, __aligned(x), __packed that are used
in cdefs.h and by several user programs.
Note that tcc recognises the __aligned__ and __packed__
attributes but does not honor them.
The resulting elf file is still not 100% correct -- if you strip it,
the program will not run (presumably there is some dangling reference).
Other than that, program do seem to run correctly.
I am going to submit the patch upstream to see if the maintainers
want to integrate it
cheers
luigi
3. -include, -M and other preprocessor directives
patch-z1-preproc (name chosen because it must be applied after
the other two) implements -include, -M (and related options),
and makes tcc ignore -isystem and -std= which are often used
to build code.

View File

@ -24,28 +24,34 @@ diff -ubwr ./libtcc.c ../../work.2/tcc-0.9.25/libtcc.c
tcc_define_symbol(s, "__STDC__", NULL);
tcc_define_symbol(s, "__STDC_VERSION__", "199901L");
#if defined(TCC_TARGET_I386)
- tcc_define_symbol(s, "__i386__", NULL);
+ tcc_define_symbol(s, "__i386__", "1");
+ tcc_define_symbol(s, "__i386", "1");
+ tcc_define_symbol(s, "i386", "1");
tcc_define_symbol(s, "__i386__", NULL);
+ tcc_define_symbol(s, "__i386", NULL); /* NULL defaults to "1" */
+ tcc_define_symbol(s, "i386", NULL);
#endif
#if defined(TCC_TARGET_X86_64)
tcc_define_symbol(s, "__x86_64__", NULL);
@@ -1802,8 +1812,15 @@
#ifdef TCC_TARGET_PE
tcc_define_symbol(s, "_WIN32", NULL);
@@ -1802,6 +1812,14 @@
#else
- tcc_define_symbol(s, "__unix__", NULL);
- tcc_define_symbol(s, "__unix", NULL);
+ tcc_define_symbol(s, "__unix__", "1");
+ tcc_define_symbol(s, "__unix", "1");
+ tcc_define_symbol(s, "unix", "1");
tcc_define_symbol(s, "__unix__", NULL);
tcc_define_symbol(s, "__unix", NULL);
+ tcc_define_symbol(s, "unix", NULL);
+#if defined(__FreeBSD__)
+#define str(s) #s
+ tcc_define_symbol(s, "__FreeBSD__", str( __FreeBSD__));
+ tcc_define_symbol(s, "__INTEL_COMPILER", "1");
+#undef str
+ tcc_define_symbol(s, "__aligned(x)", "__attribute__((__aligned__(x)))");
+ tcc_define_symbol(s, "__packed", "__attribute__((packed))");
+#endif
#if defined(__linux)
tcc_define_symbol(s, "__linux__", NULL);
tcc_define_symbol(s, "__linux", NULL);
@@ -1834,6 +1841,9 @@
tcc_define_symbol(s, "__TINYC__", NULL);
/* tiny C & gcc defines */
+ tcc_define_symbol(s, "__CC_SUPPORTS___INLINE", NULL);
+ tcc_define_symbol(s, "__builtin_inline(x,y)", "(x)");
+ tcc_define_symbol(s, "__PRETTY_FUNCTION__", "__FUNCTION__");
tcc_define_symbol(s, "__SIZE_TYPE__", "unsigned int");
tcc_define_symbol(s, "__PTRDIFF_TYPE__", "int");
#ifdef TCC_TARGET_PE

View File

@ -0,0 +1,223 @@
diff -ubwr --exclude .svn ./libtcc.c /usr/ports-luigi/tcc/work/tcc-0.9.25/libtcc.c
--- ./libtcc.c 2009-12-06 14:35:51.000000000 +0100
+++ /usr/ports-luigi/tcc/work/tcc-0.9.25/libtcc.c 2009-12-06 14:34:34.000000000 +0100
@@ -1108,7 +1108,15 @@
bf->fd = fd;
bf->buf_ptr = bf->buffer;
bf->buf_end = bf->buffer;
+ if (s1->include_len <= 0) {
bf->buffer[0] = CH_EOB; /* put eob symbol */
+ } else { /* add the list of -include */
+ if (s1->include_len >= sizeof(bf->buffer))
+ error("too many '-include directives %s\n", s1->include_buf);
+ memcpy(bf->buf_ptr, s1->include_buf, s1->include_len);
+ bf->buffer[s1->include_len] = CH_EOB; /* put eob symbol */
+ s1->include_len = -s1->include_len;
+ }
pstrcpy(bf->filename, sizeof(bf->filename), filename);
#ifdef _WIN32
normalize_slashes(bf->filename);
@@ -1945,6 +1955,9 @@
if (ext[0])
ext++;
+ /* enable -include on each new file */
+ if (s1->include_len < 0)
+ s1->include_len = -s1->include_len;
/* open the file */
saved_file = file;
file = tcc_open(s1, filename);
@@ -2121,7 +2134,9 @@
{
char buf[1024];
- s->output_type = output_type;
+ s->output_type = output_type & 7;
+ s->mode_m = output_type & 8;
+ output_type = s->output_type;
if (!s->nostdinc) {
/* default include paths */
diff -ubwr --exclude .svn ./tcc.c /usr/ports-luigi/tcc/work/tcc-0.9.25/tcc.c
--- ./tcc.c 2009-05-18 16:27:06.000000000 +0200
+++ /usr/ports-luigi/tcc/work/tcc-0.9.25/tcc.c 2009-12-06 13:42:09.000000000 +0100
@@ -66,6 +66,7 @@
static int multiple_files;
static int print_search_dirs;
static int output_type;
+static int mode_m;
static int reloc_output;
static const char *outfile;
static int do_bench = 0;
@@ -111,6 +112,10 @@
TCC_OPTION_w,
TCC_OPTION_pipe,
TCC_OPTION_E,
+ TCC_OPTION_M, /* -M and related options */
+ TCC_OPTION_std, /* -std= */
+ TCC_OPTION_isystem, /* -isystem x */
+ TCC_OPTION_include, /* -include x */
};
static const TCCOption tcc_options[] = {
@@ -148,6 +153,10 @@
{ "w", TCC_OPTION_w, 0 },
{ "pipe", TCC_OPTION_pipe, 0},
{ "E", TCC_OPTION_E, 0},
+ { "M", TCC_OPTION_M, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP },
+ { "std=", TCC_OPTION_std, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP },
+ { "isystem", TCC_OPTION_isystem, TCC_OPTION_HAS_ARG },
+ { "include", TCC_OPTION_include, TCC_OPTION_HAS_ARG },
{ NULL },
};
@@ -399,10 +408,45 @@
}
}
break;
+ case TCC_OPTION_include:
+ {
+ int len = strlen(optarg) + s->include_len + 12; /* #include ""\n */
+ char *dst;
+ s->include_buf = (s->include_len == 0) ?
+ tcc_malloc(len + 1) :
+ tcc_realloc(s->include_buf, len + 1);
+ dst = s->include_buf + s->include_len;
+ sprintf(dst, "#include \"%s\"\n", optarg);
+ s->include_len = len; /* exclude '\0' */
+ }
+ break;
+ case TCC_OPTION_isystem:
+ break; /* ignore isystem */
+ case TCC_OPTION_std:
+ break; /* ignore -std= */
+ case TCC_OPTION_M:
+ mode_m |= 8;
+ if (optarg[0] == '\0') /* plain -M */
+ ;
+ else if (optarg[0] == 'D') /* add output filename */
+ ;
+ else if (optarg[0] == 'F') { /* output filename */
+ if (optind < argc)
+ outfile = argv[optind++];
+ } else if (optarg[0] == 'T') { /* target filename */
+ if (optind < argc)
+ s->target_name = argv[optind++];
+ } else if (optarg[0] == 'P') { /* phony filename */
+ ;
+ } else {
+ goto l_default;
+ }
+ /* FALLTHROUGH */
case TCC_OPTION_E:
output_type = TCC_OUTPUT_PREPROCESS;
break;
default:
+l_default:
if (s->warn_unsupported) {
unsupported_option:
warning("unsupported option '%s'", r);
@@ -502,7 +546,7 @@
start_time = getclock_us();
}
- tcc_set_output_type(s, output_type);
+ tcc_set_output_type(s, output_type | mode_m);
/* compile or add each files or library */
for(i = 0; i < nb_files && ret == 0; i++) {
diff -ubwr --exclude .svn ./tcc.h /usr/ports-luigi/tcc/work/tcc-0.9.25/tcc.h
--- ./tcc.h 2009-05-18 16:27:06.000000000 +0200
+++ /usr/ports-luigi/tcc/work/tcc-0.9.25/tcc.h 2009-12-06 13:28:32.000000000 +0100
@@ -475,6 +475,10 @@
/* output file for preprocessing */
FILE *outfile;
+ int mode_m; /* tcc -M */
+ const char *target_name; /* set with -MT or -MQ */
+ char *include_buf; /* -include ... */
+ int include_len; /* length of -include ... */
/* for tcc_relocate */
int runtime_added;
diff -ubwr --exclude .svn ./tccpp.c /usr/ports-luigi/tcc/work/tcc-0.9.25/tccpp.c
--- ./tccpp.c 2009-05-18 16:27:06.000000000 +0200
+++ /usr/ports-luigi/tcc/work/tcc-0.9.25/tccpp.c 2009-12-05 15:18:13.000000000 +0100
@@ -2897,6 +2897,7 @@
Sym *define_start;
BufferedFile *file_ref;
int token_seen, line_ref;
+ const char *base_file;
preprocess_init(s1);
define_start = define_stack;
@@ -2908,6 +2909,15 @@
line_ref = 0;
file_ref = NULL;
+ base_file = file->filename;
+ if (s1->mode_m) {
+ int l = strlen(base_file);
+ if (s1->target_name)
+ fprintf(s1->outfile, "%s: %s", s1->target_name, base_file);
+ else
+ fprintf(s1->outfile, "%.*s.o: %s", l-2, base_file, base_file);
+ }
+
for (;;) {
next();
if (tok == TOK_EOF) {
@@ -2919,16 +2929,25 @@
token_seen = 0;
} else if (!token_seen) {
int d = file->line_num - line_ref;
+ if (s1->mode_m) {
+ if (file != file_ref && file->filename != base_file &&
+ !search_cached_include(s1, '>', file->filename))
+ fprintf(s1->outfile, " \\\n %s", file->filename);
+ } else {
if (file != file_ref || d < 0 || d >= 8)
fprintf(s1->outfile, "# %d \"%s\"\n", file->line_num, file->filename);
else
while (d)
fputs("\n", s1->outfile), --d;
+ }
line_ref = (file_ref = file)->line_num;
token_seen = 1;
}
+ if (!s1->mode_m)
fputs(get_tok_str(tok, &tokc), s1->outfile);
}
+ if (s1->mode_m)
+ fprintf(s1->outfile, "\n");
free_defines(define_start);
return 0;
}
diff -ubwr --exclude .svn ./tcc.c /usr/ports-luigi/tcc/work/tcc-0.9.25/tcc.c
--- ./tcc.c 2009-12-06 15:42:02.000000000 +0100
+++ /usr/ports-luigi/tcc/work/tcc-0.9.25/tcc.c 2009-12-06 15:42:40.000000000 +0100
@@ -40,8 +40,11 @@
"Preprocessor options:\n"
" -E preprocess only\n"
" -Idir add include path 'dir'\n"
+ " -include f #include file 'f' before everything else\n"
" -Dsym[=val] define 'sym' with value 'val'\n"
" -Usym undefine 'sym'\n"
+ " -M generate include list. Implies -E\n"
+ " -MT file use 'file' as target for -M.\n"
"Linker options:\n"
" -Ldir add library path 'dir'\n"
" -llib link with dynamic or static library 'lib'\n"
@@ -58,6 +61,12 @@
#ifdef CONFIG_TCC_BACKTRACE
" -bt N show N callers in stack traces\n"
#endif
+ "Ignored options (for gcc compatibility):\n"
+ " -std=X \n"
+ " -MD name\n"
+ " -MP\n"
+ " -isystem dir\n"
+
);
}