Before VC2005, the time macros (time, time_t, localtime, etc) were
32 bit on 32 bit platforms, but they became 64 in VC2005.
This works even on XP 32 (_time64 etc do exist in XP32 - and in tcc).
However, tv_sec in struct timeval (which for msvc is in winsock2.h)
remains 32 bit to this day on 32 bit platforms, and dlls which were
not recompiled remain with time 32, possibly at the API boundary.
Due to these, and maybe more, mingw w64 decided to keep the time
macros 32 bit on 32 bit platforms, with __MINGW_USE_VC2005_COMPAT
override (which does nothing in mingw w64 except time -> time64).
It's not perfect, but it allows some existing code to easily switch
to 64 bit time without redefining time etc, e.g. used by libressl:
https://github.com/libressl/portable/blob/master/README.mingw.md
Before, it was impossible to enable the 64 bit time macros in tcc 32.
This commit adds support for __MINGW_USE_VC2005_COMPAT in tcc as well,
which, like in mingw w64, affects only the 32->64 time macros, and is
a cheap way to get 64 bit time in existing code in some 32 bit apps.
The additional #ifndef _USE_32BIT_TIME_T is unrelated to the override,
and avoids a warning (and nothing else) when the code explicitly
defines it - which is allowed in MSVC, and also guarded in mingw w64.
Relevant current quote from the libressl link above:
------- >8 ---------
Why the -D__MINGW_USE_VC2005_COMPAT flag on 32-bit systems?
An ABI change introduced with Microsoft Visual C++ 2005 (also known as
Visual C++ 8.0) switched time_t from 32-bit to 64-bit. It is important
to build LibreSSL with 64-bit time_t whenever possible, because 32-bit
time_t is unable to represent times past 2038 (this is commonly known
as the Y2K38 problem).
If LibreSSL is built with 32-bit time_t, when verifying a certificate
whose expiry date is set past 19 January 2038, it will be unable to
tell if the certificate has expired or not, and thus take the safe
stance and reject it.
In order to avoid this, you need to build LibreSSL (and everything
that links with it) with the -D__MINGW_USE_VC2005_COMPAT flag. This
tells MinGW-w64 to use the new ABI.
64-bit systems always have a 64-bit time_t and are not affected by
this problem.
with -Wl,-oformat=binary, executable code should come first.
(for linux kernel image for example)
Also:
- simplify RELRO sections: create them as readonly, but add
SHF_WRITE flag later when needed (i.e. relocations do exist)
- tcc.h etc: exclude eh_frames on non-elf platforms
- tccelf.c:tcc_load_object_file(): don't load debug sections when
linking without -g (special dwarf case in relocate_section()
wont work when dwlo/hi were not initialized).
- tcc.c: avoid loop if something fails (ret < 0) without message
(while failing without message should not happen either)
- tccelf.c:tcc_load_alacarte: give message
- tccpp.c: treat '# 123xyz' in asm file as comment
- lib/Makefile: cleanup
- libtcc.c: tcc_add_library(): fallback to try filename as is
(also remove tcc_add_library_err())
patch originally made to prove correctness (comparing stages)
with tinycc compiling gcc 2.95.3 which would assign registers
differently (but still correctly) when compiled with tcc without
this option).
Also: fixes get_temp_local_var() which on 32-bit systems
happened to return a temporary location that was still
in use because its offset was changed on the vstack
(incremented by four in gv() to load the second register
of a long long).
Also: optimize vrot-t/b (slightly) by using one memmove
instead of moving elements one by one in a loop.
- output correct line number with "error: duplicate case value"
- libtcc.c:error1(): support specific line numbers with "%i:"
tcc_error("%i:message ...", line_num, ...);
Also:
- simplify signed/unsigned switch compare
- optimize implicit case ranges such as
case 1: case 2: case 3: ...
- simplify llong constant propagation in gen_opic()
- rename Sym.ncl to Sym.cleanup_func
This requires adding .eh_frame and .eh_frame_hdr sections.
There are 3 new functions to setup the sections:
tcc_eh_frame_start: create cie in .eh_frame
tcc_debug_frame_end: add fde in .eh_frame for every function
tcc_eh_frame_hdr: create .eh_frame_hdr
The PT_GNU_EH_FRAME header is created.
The dwarf read functions are moved from tccrun.c to tcc.h
The backtrace() function is not supported on all targets.
windows, apple, bsd and arm are disabled.
arm uses its own sections .ARM.extab and .ARM.exidx.
endbr64 has no operand but comes with a ModR/M byte. Handle it in the
same way as *fence instructions.
Co-authored-by: Yao Zi <ziyao@disroot.org>
Signed-off-by: Yao Zi <ziyao@disroot.org>
Signed-off-by: John Nunley <dev@notgull.net>
It has the same effect as call.
Co-authored-by: Yao Zi <ziyao@disroot.org>
Signed-off-by: Yao Zi <ziyao@disroot.org>
Signed-off-by: John Nunley <dev@notgull.net>
We already have sys/unistd.h, but the standard place for it is at
the include root, so make that work too, but keep sys/unistd.h for
backward compatibility.
Since commit 45cff8f0 tcc eventually generates object files
of non-even size.
tccelf.c:
- check ARFMAG for better invalid archive detection
- file_offset needs to be aligned, not the size (just a nitpick)
lib/Makefile:
- remake everything when tcc did change
compiling with tcc and linking with gcc gives error:
tcc -c a.c
gcc a.o
usr/bin/ld: a.o: .symtab local symbol at index 0 (>= sh_info of 0)
/usr/bin/ld: a.o: error adding symbols: bad value
collect2: error: ld returned 1 exit status
Solved by moving call to sort_syms.
Instead of always emitting movabs, emit a regular mov or a xor.
Slims down sequences like:
movabs $0,%rax
mov %rsi,%rax
To:
xor %eax,%eax // also zeroes upper word
mov %rsi,%rax
Future work is to just emit:
xor %esi,%esi
Use `t1` instead of `t0` for the cases when `rr` is not set so `t0` is
used by default and this happens:
lui t0, XXX
add t0, t0, t0
Instead, now we do:
lui t1, XXX
add t0, t0, t1
This commit fixes the case where the register of for the Extended Asm
input or output is known. Before this commit, the following case:
register long __a0 asm ("a0") = one;
asm volatile (
"ecall\n\t"
: "+r" (__a0) // NOTE the +r here
);
Didn't treat `a0` as an input+output register (+ contraint) as the code
skipped the constraint processing when the register was already chosen
(instead of allocated later).
This issue comes from f081acbfba, that was
taken as a reference in every other Extended Assembler implementation.
NOTE: In order to be able to deal with general-purpose vs floating-point
registers, this commit adds a flag in the 6th bit of the register. If
set, it means the register is a floating-point one. This affects all the
assembler.