Re: [Tinycc-devel] a.out support (was Re: add an executable format?)

2023-02-04 Thread tccm
Hello Brian,

On Sat, Feb 04, 2023 at 02:28:32PM +, Brian Callahan wrote:
> One thing I noticed in your elf2aout.c comments is that Minix-2 only
> supports 14-character file names. You can make the temp file much
> shorter if needed (e.g., hard code it to be something like "temp.aout").

This would introduce possible collisions between simultaneously run
compilations to different files. A cleaner solution would be to use
a randomly generated name but even this can be a can of worms on old
systems.

In practice I would find it sufficient and better for simplicity,
to add a warning in the man page about the possible naming issues.

Best of all would be of course to support aout internally and write the
resulting file directly. Then tcc could be also built smaller for aout
platforms, by dropping elf and dynamic linking. Achieving this would be
probably not easy, given that tcc was made for elf from the beginning
(? what do tcc gurus say?).

> Would it be possible for you to share binaries of your new TCC? I
> finally got Minix-2 i386 running on VirtualBox and it would be nice to
> try out TCC there.

Hopefully tomorrow. Let me get back to you then.

Cheers
/tccm


___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] a.out support (was Re: add an executable format?)

2023-02-04 Thread Brian Callahan
Hello --

On 2/4/2023 8:31 AM, tccm wrote:
> On Sat, Jan 21, 2023 at 07:03:52AM +0100, tccm wrote:
>> I will test your patch and report here.
> 
> Hello Brian,
> 
> Many thanks for your code, it helped a lot.
> 

Glad to hear that it helped.

One thing I noticed in your elf2aout.c comments is that Minix-2 only
supports 14-character file names. You can make the temp file much
shorter if needed (e.g., hard code it to be something like "temp.aout").

Would it be possible for you to share binaries of your new TCC? I
finally got Minix-2 i386 running on VirtualBox and it would be nice to
try out TCC there.

~Brian

___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] FWD: Can't build for riscv64 or arm64

2023-02-04 Thread Christian Jullien
This post does not solves missing types but be aware that more recent gcc 
versions changed the names to [unsigned] __int128

Hence
__uint128_t => unsigned __int128
__int128_t  => __int128

Old names remain for compatibility and are *strictly* equivalent.
For example, starting with gcc v11.x, sdt::numeric_limits and typeinfo (C++) 
return the same exact values for old and new names and are totally 
interchangeable.

IMHO, if tcc implements one day 128 bits, it should be with new name (+ a 
typedef for older names).

C. 

-Original Message-
From: tinycc-devel-bounces+eligis=orange...@nongnu.org 
[mailto:tinycc-devel-bounces+eligis=orange...@nongnu.org] On Behalf Of Detlef 
Riekenberg
Sent: Friday, February 03, 2023 19:11
To: tinycc-devel@nongnu.org
Subject: *** SPAM *** Re: [Tinycc-devel] FWD: Can't build for riscv64 or arm64

Hi Sagar

tcc has no support for 128bit int types.
__uint128_t
__int128_t


You might try with a replacement (typedef struct with 2x uint64)
This should be at least enough for the structsize for the typedef in signal.h,
but acessing the elements in the code you try to compile will propably fail

-- 
Bye bye ... Detlef


> When building lib/bt-exe.c , it imports ../tccrun.c
> Which throws error
> 
> /usr/include/bits/signal.h:14: error ';' expected (got "__uint128_t"
> 
> /usr/include/bits/signal.h is as follows:
> 
> typedef struct {
> __uint128_t vregs[32];
> unsigned int fpsr;
> unsigned int fpcr;



___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


[Tinycc-devel] a.out support (was Re: add an executable format?)

2023-02-04 Thread tccm
On Sat, Jan 21, 2023 at 07:03:52AM +0100, tccm wrote:
> I will test your patch and report here.

Hello Brian,

Many thanks for your code, it helped a lot.

I did not use the upstream build scripts/tools (including configure and
Makefile), they are not applicable on older platforms. IOW I did not
test this part of your patch.

The attached variant of elf2aout.c and a corresponding patch to other
files have been successfully tested on Minix-2.i386 and Minix-vmd.
After a bootstrap the compiler becomes self-hosted.
(The C standard library is rebuilt with Tiny CC to be available as elf)

This code produces stripped "common I" executables (symtab conversion
is skipped) with a 1MB stack+memory limit which afterwards can be adjusted
with Minix chmem utility.

I think that the changes as in the patch are very light and could be added
to upstream (suitably ifdef-conditioned) without adding any remarkable
weight to tcc. Using current configure to activate them can not work on
Minix-2 (unfortunately) but this does not make them unusable.

elf2aout.c contains platform-specific details. It works for Minix-2
and Minix-vmd but would need some ifdefs for other platforms. Would it
harm to add it to upstream, as a reference for possible future needs
and developers?

Improvements are of course possible, not least supporting separate I
or handling symbol tables, but this was beyond my current needs and is
left for a possible later exercise.

Thanks again, it is very useful to have a fast and compact C99-toolchain
on these lightweight kernels / OS.

Cheers
/tccm
diff -u -r a/tinycc-20a1ebf/i386-link.c b/tinycc-20a1ebf/i386-link.c
--- a/tinycc-20a1ebf/i386-link.c	2022-08-18 09:34:36.0 +
+++ b/tinycc-20a1ebf/i386-link.c	2023-02-03 13:07:51.488566020 +
@@ -12,7 +12,7 @@
 
 #define R_NUM   R_386_NUM
 
-#define ELF_START_ADDR 0x08048000
+#define ELF_START_ADDR 0
 #define ELF_PAGE_SIZE  0x1000
 
 #define PCRELATIVE_DLLPLT 0
Only in b/tinycc-20a1ebf: i386-link.c.
Only in b/tinycc-20a1ebf: i386-link.c_
diff -u -r a/tinycc-20a1ebf/libtcc.c b/tinycc-20a1ebf/libtcc.c
--- a/tinycc-20a1ebf/libtcc.c	2022-08-18 09:34:36.0 +
+++ b/tinycc-20a1ebf/libtcc.c	2023-02-03 13:07:51.468566019 +
@@ -818,6 +818,8 @@
 s->ppfp = stdout;
 /* might be used in error() before preprocess_start() */
 s->include_stack_ptr = s->include_stack;
+/* do not try dynamic linking on this platform */
+s->static_link = 1;
 
 tccelf_new(s);
 
diff -u -r a/tinycc-20a1ebf/tcc.c b/tinycc-20a1ebf/tcc.c
--- a/tinycc-20a1ebf/tcc.c	2022-08-18 09:34:36.0 +
+++ b/tinycc-20a1ebf/tcc.c	2023-02-03 13:07:51.456566019 +
@@ -397,6 +397,15 @@
 if (done && 0 == t && 0 == ret && s->do_bench)
 tcc_print_stats(s, end_time - start_time);
 
+#ifdef TCC_GENERATE_AOUT
+{   int e2a;
+if (s->output_type == TCC_OUTPUT_EXE) {
+if ((e2a = elf2aout(s->outfile)) != 0)
+return e2a;
+}
+}
+#endif
+
 tcc_delete(s);
 if (!done)
 goto redo; /* compile more files with -c */
diff -u -r a/tinycc-20a1ebf/tccgen.c b/tinycc-20a1ebf/tccgen.c
--- a/tinycc-20a1ebf/tccgen.c	2022-08-18 09:34:36.0 +
+++ b/tinycc-20a1ebf/tccgen.c	2023-02-03 13:07:51.476566020 +
@@ -1731,7 +1731,7 @@
 (vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST) {
 /* CPUs usually cannot use float constants, so we store them
generically in data segment */
-init_params p = { rodata_section };
+init_params p = { data_section };
 unsigned long offset;
 size = type_size(>type, );
 if (NODATA_WANTED)
@@ -5344,7 +5344,7 @@
 mk_pointer();
 type.t |= VT_ARRAY;
 type.ref->c = len;
-sec = rodata_section;
+sec = data_section;
 vpush_ref(, sec, sec->data_offset, len);
 if (!NODATA_WANTED)
 memcpy(section_ptr_add(sec, len), funcname, len);
@@ -5368,7 +5368,7 @@
 mk_pointer();
 type.t |= VT_ARRAY;
 memset(, 0, sizeof(AttributeDef));
-ad.section = rodata_section;
+ad.section = data_section;
 decl_initializer_alloc(, , VT_CONST, 2, 0, 0);
 break;
 case '(':
@@ -7944,7 +7944,7 @@
 while ((tp->t & (VT_BTYPE|VT_ARRAY)) == (VT_PTR|VT_ARRAY))
 tp = >ref->type;
 if (tp->t & VT_CONSTANT) {
-		sec = rodata_section;
+		sec = data_section;
 } else if (has_init) {
 		sec = data_section;
 /*if (tcc_state->g_debug & 4)
diff -u -r a/tinycc-20a1ebf/tcc.h b/tinycc-20a1ebf/tcc.h
--- a/tinycc-20a1ebf/tcc.h	2022-08-18 09:34:36.0 +
+++ b/tinycc-20a1ebf/tcc.h	2023-02-03 13:07:51.436566019 +
@@ -1815,6 +1815,12 @@
 #define dwarf_str_section   s1->dwarf_str_section
 #define dwarf_line_str_section  s1->dwarf_line_str_section
 
+/*  elf2aout.c  */
+#ifdef