Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] mob from TinyCC:mob #51

Open
wants to merge 302 commits into
base: mob
Choose a base branch
from
Open

[pull] mob from TinyCC:mob #51

wants to merge 302 commits into from

Conversation

pull[bot]
Copy link

@pull pull bot commented Oct 14, 2022

See Commits and Changes for more details.


Created by pull[bot]

Can you help keep this open source service alive? 💖 Please sponsor : )

hermantb and others added 26 commits December 11, 2022 08:23
Add new file lib/builtin.c
Modify include/tccdefs.h, lib/Makefile to compile it.
Update tests/tcctest.c to test it.
We already support popcnt, add lzcnt and tzcnt as well.

Signed-off-by: Mathias Krause <[email protected]>
Update configure and remove dll=no for Darwin.
Also removed dwarf=$dwarf because this is not a config option.

In tccelf.c only add __PAGEZERO if stabs and executable.

In tccrun.c correct rt_printline_dwarf code for dll.

In tests/Makefile disable dlltest with PIC for Darwin because object
format of .o file is still in elf.

In tccmacho.c add dll support and and rpath support.
Corrected trie code. For some reason symbol 'xx' should be after 'xx1'.
Corrected weak symbol support for old macho code.
Used R_JMP_SLOT instead of R_DATA_PTR in check_relocs.
Macho uses bind/rebase instead of dynsym so disable them for relocate_sections.
Needed when using ...libtcc1-usegcc=yes in lib/Makefile.

lib/bcheck.c: Add __clang__ for pragma diagnostic
lib/bt-log.c: Add pragma diagnostic as in lib/bcheck.c
lib/builtin.c: Add a lot of alias code to allow building with gcc/clang
lib/stdatomic.c: Same as lib/builtin.c
lib/tcov.c: Avoid clang compiler warning
Export now all global symbols in export trie instead of only text
symbols.

I wrote too much data into dylib file because I did not check
for sk_unknown/sk_discard/sk_uw_info.

Simplified code in tccrun.c
With these option I can now built several packages without problem.
There are a lot of options we can add so I tried to implement the
minumum.

Add the following options:
dynamiclib		same as -shared
flat_namespace		default/ignored
two_levelnamespace	ignored
undefined		default/ignored
install_name		name of dynmic lib
compatibility_version	version dynamic lib
current_version	version version dynamic lib

-Wl options:
all_load		same as whole-archive
force_load		same as whole-archive with lib
single_module		ignored
On macos we cannot use the ar because is does not support elf files
and then does not generate a symbol table.
The solution is to use 'tcc -ar'. The problem now is that some
pacages first built an archive with 'tcc -ar c' and later extracts
the archive with 'tcc -ar x' and built with this a dylib file.
The 'tcc -ar x' failed. So I implemented it. I also added the t
option because it was simple to do,
Also: return all of 'cumofs' (no extra '+' required at caller)
The problem occurs when a shared library creates a pointer to
a function and then the application also uses this function.
Changed -1 into -2 for plt_offset,
If multiple rpaths are specified then output multiple LC_RPATH load
commands instead of one with : seperator.
…l,-soname. This helps configure scripts using both clang and tcc.
In tcc_load_object_file use unsigned long for size/offset.
This avoids strange sizes of sections in case of overflow.
The sections that are now larger then 4G may not work.
This avoids a hang on macos in realloc.
tcc -ar t failed sometimes because the header size was not correct.
The preprocessor line directive did not result in correct debug info
when -g was used.
Line directives like:
 #line 1 "filename"
should now work.
Macos has an offset of 1 for DW_LNS_set_file.

Also rewrite dwarf_file to not scan list twice and
move check for <command line> to this function.
grischka and others added 30 commits November 30, 2024 20:04
accept the new C2x typed enums (seems new android-NDK
headers are using that now)
Put former NATIVE_DEFINES into config.h.  Such tcc can be run
and tested directly from source more easily, like for example:

    tcc -run tcc.c -B. -run test.c

Also:
- tccelf.c: cleanup
- tccpp.c: avoid stupid clang warning
- configure: reduce -Wno- switches
- tcc.h: inline wait/post_sem()
- tccpe.c: simplify import (assume STT_NOTYPE is function)
Commit 729918e ("make: make shorter command lines", 2024-11-21) added
"-static" when $cc_name is gcc to statically link with the mingw gcc
runtime, so that tcc.exe won't depend on additional non-system dlls.

However, $cc_name is still the default value at this time - gcc,
so "-static" was unconditional, and it failed if $cc is tcc (msvcrt).

This commit instead checks the already known $cc, and restores the
ability to build tcc using tcc (if "$cc" doesn't contain "gcc").
Shells do support those, and typically simple forms do work, but
these were removed in POSIX 2024 because they are notoriously hard
to parse correctly, and shells don't always agree on the result.

Instead, use standard forms which all shells support identically.

Extreme high level overview of quotes in POSIX shell:
- WORDs without $... or glob don't need quotes (echo, =, no, x86, ...).
- a=  b=foo  c=$...  and  case $d in ...  all don't need quotes.
- IFS/glob affect command and arguments (not assignments or case..in):
  - IFS only splits direct result of $..., quotes will prevent that.
  - Glob then splits/matches *?[]      and quotes will prevent that.

POSIX "test" (see Application Usage), and shell language (quotes):
  https://pubs.opengroup.org/onlinepubs/9799919799/utilities/test.html
  https://pubs.opengroup.org/onlinepubs/9799919799/utilities/V3_chap02.html

My own quick guide:
  https://gist.github.com/avih/6752ad1e20b334b56fef120cd09c766e
The vast majority of shells do support "local", but not all, notably
AT&T ksh (default sh in illumos-based distros and Solaris), but also
some other POSIX-compliant shells, so remove "local".

print_str(), print_num() are modified trivially.

default() now uses standard "Assign Default Value" - same semantics,
and works in all shells (and POSIX).

default_conf() is identical to before, but it had and still has few
minor issues, which will be addressed in a future commit.
Add and use "assign_opt" instead of copy-pasting subshell assignment.

Slightly faster, and fixes option values with consecutive spaces,
for instance --libdir='/foo   bar' where previously `echo $opt | ...`
coalesced IFS chars because $opt was unquoted. (this is still very
likely to break, but at least now not at the options parsing).

Unrelated note:

The code does  eval opt=\"$opt\"  for every argument, to "reproduce
autotools behavior" (commit 2e7a1af, 2012-06-12, Thomas Preud'homme).

This is questionable, and not fun (try: --config-x='"; echo "PWNED').
I emailed the author for more info, but didn't get a reply aftre few
days, and without real-world use cases, I think it should be removed.
Trivial, but less noisy when reading, and nicer for new code.

The code still adds the value[s] unconditionaly without checking for
duplicates or spaces in values - both are bad, but next commit will.
$confvars is not supposed to hold the same key more than once, and
spaces in values won't be parsed correctly. Additionally, it's later
iterated using shell IFS-split - which will also apply globs.

We now abort if the value IFS-splits badly (spaces/glob/empty).

We now warn on duplicates, but still accept them like before.

Example duplicate: --enable-static --disable-static
Example spaces:    --config-foo="bar baz"
Example glob:      --config-foo=" * "

Note that globs currently already expand at  eval opt=\"$opt\"
before we get a chance to test it (but we still detect the spaces).
See commit message of 2127206 (boilerplate var=..) about removing it.

These tests are also performed on values which configure itself adds,
but currently there are no issues with those.

Also, default_conf() now uses confvars_has, which fixes the following:
- False-positive if the key is a substring of existing key or value.
- Incorrect test if the value contains '=' or sh pattern chars *?[] .
No-op, because current default_conf calls don't have such issues.
Add very few missing quotes where IFS/globs were applied to arbitrary
user input (commands, arguments, but not assignments or case $var in.
In fn_makelink $dn/$2/$f don't have IFS/globs).

While configure now handles it correctly, there are 2 issues:
- eval opt=\"$opt\"  coalesces IFS chars (--prefix="$HOME/x   y").
- Even with the eval removed, (gnu) make still fails to find it.

I made few quick experiments with quoting these values in config.mak,
but that had no impact, and make -d was not helpful. Was worth a try.

So no spaces in paths, but at least configure can handle the src path.
Don't try ln again if it failed, it won't have better luck next time.
Elsewhere at configure the value of $mingw32 is expected to be
exactly either yes or no (not empty, not caps, etc), and while it
complies internally, it also accepts arbitrary override value.

Clarify acceptable values, and simplify the parsing.
just clear s1->static_link before loading msvcrt etc.

Also:
- configure: get cc_version/name when making a cross compiler too
- configure: fix android triplets
- Makefile: remove CONFIG_TCC_CROSS, check TCC_TARGET_xxx instead
- libtcc.c: parse some linker option arguments more correctly
- tccelf.c: fix a versym problem with clang on android
- lib/Makefile, build-tcc.bat: bcheck.c now includes config.h
Commit a522213 ("tccpe.c: never assume static...") removed the global
-I$(TOP) for cleaner lib build, and ensured that it is added for
bcheck.c as it now includes config.h, but forgot that bt-exe.c also
needs config.h, as it includes ../tccrun.c which includes it.

Also, the explicit tccrun.c prerequisite for bt-exe.c is not required,
as all *.o lib files depend on $(TCC), which depends on libtcc, which
depends on tccrun.c .

Also, at win32/built-tcc.bat, while bcheck.c needs -I.. for config.h,
bt-exe.c doesn't, as ../tccrun.c does find it where it expects it.
With recent changes I got:
/usr/lib/crtbegin.o: error: Invalid relocation entry [ 2] '.rela.text' @ 0000007a
And:
libtcc.o: error: section type conflict: .eh_frame 01 <> 70000001
There was a duplicate definition of LDBL_MAX_EXP, which this commit
removes.

There was a missing definition for LDBL_MAX_10_EXP, which this
commit adds.

I've confirmed the value of LDBL_MAX_10_EXP using gcc on an AARM64
Debian system (gcc 8.3.0).  I've only indirectly confirmed the value
on RISCV (using "#if ... #error" on godbolt.org).  I'm reasonably
sure this update is correct, but someone should confirm it before
merging to "mob".
when there are no other errors then exit tcc with the exit cude
from tcc_run() (messed up in dd2e5f8)

Also in tccrun.c, use a more exotic random value to replace zero
with 'exit(0)' in user code (because lonhjmp(jb, c) needs c != 0)
It looks like this is in the Makefile build, and it appears to be
necessary to make __builtin_ctzll available.
In x86_64-gen.c/i386-gen.c, gfunc_call will generate structure store
for bt == VT_STRUCT. Before generating any code, it is needed fetch
cpu flag.
As #ifdef TCC_TARGET_PE, gfunc_call() forgot to do this.
Noticed this when the crt1.o file on an updated riscv had a
text section where the size is not multiple of align.
This file is loaded first and when the c code is then compiled
the code is not aligned any more.
This results in:
alignment of code section not multiple of 4
in riscv64-gen.c
As it will cause printf("%llu\n", (unsigned long long)1e19); output
9223372036854775808
instead of
10000000000000000000
Testcase 134 only worked on x86_64 and i386 not on other targets.
Using:
  #define LINE1 10
  #line LINE1
  #define LINE2 20
  #define FILE "file"
  #line LINE2 FILE
Should now work.

Add new testcase tests/pp/23.S
I noticed that '#line 0x20' worked.
So use the preprocessor macros.
Compatible with ld.bfd, gold, lld and mold. Also, document existing
behaviour of LD_SO environment variable
TCC treats -nostdlib and -Wl,-nostdlib as equivalent, but on other compilers
which call a discrete linker, -nostdlib behaves as on tcc (not adding
startfiles/libc/endfiles) by modifying the ld command line, but -Wl,-nostdlib
adds -nostdlib to the ld cmdline, which stops the linker searching the default
directories for libraries.
eg. -l :crti.o, with the same meaning as for other linkers (search library
paths for an exact match)

Also clean up some copy/pasting
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.