tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] Linking system dylibs on macOS 11+


From: Christian Jullien
Subject: Re: [Tinycc-devel] Linking system dylibs on macOS 11+
Date: Thu, 8 Jul 2021 08:51:20 +0200

Hi,

 

I get the two warnings with gcc, not with clang:

./configure --cc=gcc --cpu=x86_64

gcc -o tccmacho.o -c tccmacho.c -DCONFIG_USR_INCLUDE="\"/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include\"" -DTCC_TARGET_X86_64 -DTCC_TARGET_MACHO        -DONE_SOURCE=0 -Wall -O2 -Wdeclaration-after-statement -fno-strict-aliasing -Wno-pointer-sign -Wno-sign-compare -Wno-unused-result -Wno-format-truncation -I.

In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/string.h:194,

                 from tcc.h:35,

                 from tccmacho.c:18:

tccmacho.c: In function 'add_segment':

tccmacho.c:265:5: warning: '__builtin_strncpy' specified bound 16 equals destination size [-Wstringop-truncation]

  265 |     strncpy(sc->segname, name, 16);

      |     ^~~~~~~

In function 'add_section',

    inlined from 'collect_sections' at tccmacho.c:649:22,

    inlined from 'macho_output_file' at tccmacho.c:812:9:

tccmacho.c:285:5: warning: '__builtin_strncpy' specified bound 16 equals destination size [-Wstringop-truncation]

  285 |     strncpy(sec->sectname, name, 16);

      |     ^~~~~~~

 

Are you on Big Sur M1 (= aarch64) or Big Sur Intel? Rosetta comes only with M1 and it translates Intel code to Aarch64 on the fly.

 

My previous attempt to build tcc on M1 was in fact to build a M1 (Aarch64) binary cross-compiler for x86_64. This way, tcc is a native binary on M1 which produce x86_64 user code translated by Rosetta (on a M1) to produce a workable program.

Most (not to say about all) test fails.

 

I get a much better result if I compile tcc as native x86_64 binary using:

./configure --extra-cflags="-arch x86_64" --extra-ldflags="-arch x86_64" --cpu=x86_64

 

Make test gives NO error at all!!!!

 

To summarize:

On Big Sur Intel, I recommend ./configure; make

On Big Sur M1, I recommend ./configure --extra-cflags="-arch x86_64" --extra-ldflags="-arch x86_64" --cpu=x86_64

 

I’ll try to make the later options the ./configure default on M1.

 

Many thanks all to make M1 support happen.

 

C.

 

From: Tinycc-devel [mailto:tinycc-devel-bounces+eligis=orange.fr@nongnu.org] On Behalf Of Sushant Pandurangi
Sent: Wednesday, July 07, 2021 21:41
To: tinycc-devel@nongnu.org
Subject: Re: [Tinycc-devel] Linking system dylibs on macOS 11+

 

Hello Christian,

 

Thanks for the Windows patches and the long double fix.

 

To clarify about tcc -run, I'm not using --cpu=x86-64 at all, I am on a fresh M1 and Rosetta is not even installed. Here, `tcc -run` starts running main() and very simple stuff (like Hello World) works already.

 

On the other hand in a cross-compiler config, I wonder if tcc -run can work at all -- not unless Rosetta can do in-memory translation of the JIT'd x86-64 code.

 

The 2 warnings at tccmacho.c:265/285 -- those are not from my code, did they show up only after my patch? I wonder why. I'm not familiar with that function and probably not the best person to make a fix.

 

To Herman, thanks a lot for catching the memcheck issues.



Regards,

Sushant

 

Date: Wed, 7 Jul 2021 07:55:41 +0200
From: "Christian Jullien" <eligis@orange.fr>
To: <tinycc-devel@nongnu.org>
Subject: Re: [Tinycc-devel] Linking system dylibs on macOS 11+
Message-ID: <000301d772f4$b88cf070$29a6d150$@orange.fr>
Content-Type: text/plain;        charset="utf-8"

Hello Sushant,

Your pushed patch works at 99%.

--- The details:

there are few warnings:

tccmacho.c: In function 'add_segment':
tccmacho.c:265:5: warning: '__builtin_strncpy' specified bound 16 equals destination size [-Wstringop-truncation]
 265 |     strncpy(sc->segname, name, 16);
     |     ^~~~~~~
In function 'add_section',
   inlined from 'collect_sections' at tccmacho.c:649:22,
   inlined from 'macho_output_file' at tccmacho.c:812:9:
tccmacho.c:285:5: warning: '__builtin_strncpy' specified bound 16 equals destination size [-Wstringop-truncation]
 285 |     strncpy(sec->sectname, name, 16);
     |     ^~~~~~~

--- More annoying.

BUG1: tcc -run fails because it is not supported by cross-compiler. IMHO, on macOS --cpu should not be considered as cross-compiler
------------ hello-run ------------
tcc: error: -run is not available in a cross compiler
If I remove this test:
#ifndef TCC_IS_NATIVE
           tcc_error("-run is not available in a cross compiler");
#endif

It fails with
------------ libtest ------------
dyld: lazy symbol binding failed: Symbol not found: _tcc_relocate
 Referenced from: /Users/jullien/tinycc/tests/./libtcc_test
 Expected in: flat namespace

dyld: Symbol not found: _tcc_relocate
 Referenced from: /Users/jullien/tinycc/tests/./libtcc_test
 Expected in: flat namespace

BUG2: When compiled tcc with ./configure --cpu=x86_64
Generated code is considered as a cross-compiler.
Then, when I use a long double in my code, it reaches tccgen.c(8087): tcc_error("can't cross compile long double constants");

In this specific case, both double and long double are 8 bytes but LDOUBLE_SIZE == 16

I tried this patch which seems to solve this issues. Maintainers, is it the right patch? Do you allow me to push it on mod?
If you prefer, I can surround it with #ifdef TCC_TARGET_MACHO

jullien@mobley:~/tinycc $ git diff
diff --git a/tccgen.c b/tccgen.c
index c36032a..425a001 100644
--- a/tccgen.c
+++ b/tccgen.c
@@ -8088,10 +8088,10 @@ static void init_putv(init_params *p, CType *type, unsigned long c)
#endif
                /* For other platforms it should work natively, but may not work
                   for cross compilers */
-                if (sizeof(long double) == LDOUBLE_SIZE)
-                    memcpy(ptr, &vtop->c.ld, LDOUBLE_SIZE);
-                else if (sizeof(double) == LDOUBLE_SIZE)
-                    memcpy(ptr, &vtop->c.ld, LDOUBLE_SIZE);
+                if (sizeof(long double) <= LDOUBLE_SIZE)
+                    memcpy(ptr, &vtop->c.ld, sizeof(long double));
+                else if (sizeof(double) <= LDOUBLE_SIZE)
+                    memcpy(ptr, &vtop->c.ld, sizeof(double));
#ifndef TCC_CROSS_TEST
                else
                    tcc_error("can't cross compile long double constants");

 


reply via email to

[Prev in Thread] Current Thread [Next in Thread]