aboutsummaryrefslogtreecommitdiff
Commit message (Collapse)AuthorAgeFilesLines
...
* arm64: Handle R_AARCH64_PREL32 againMichael Matz2016-12-151-0/+5
| | | | This got lost when splitting reloc handling to individual files.
* arm64: Fix largeptr testMichael Matz2016-12-151-1/+2
| | | | VT_PTR needs to be handled like VT_LLONG.
* arm64: Fix a case of dead code suppressionMichael Matz2016-12-151-4/+6
| | | | 82_nocode_wanted.c:kb_wait_2_1 was miscompiled on arm64.
* struct-layout: Allow lowering of member alignmentMichael Matz2016-12-152-2/+17
| | | | | | when an alignment is explicitely given on the member itself, or on its types attributes then respect it always. Was only allowed to increase before, but GCC is allowing it.
* Support large alignment requestsMichael Matz2016-12-153-7/+38
| | | | | | | | The linux kernel has some structures that are page aligned, i.e. 4096. Instead of enlarging the bit fields to specify this, use the fact that alignment is always power of two, and store only the log2 minus 1 of it. The 5 bits are enough to specify an alignment of 1 << 30.
* struct-layout: cleanup code a bitMichael Matz2016-12-151-94/+56
|
* bitfields: Fix MS layout some moreMichael Matz2016-12-151-4/+9
| | | | | | | | | | | | | | | | Another corner case: struct foo6_1 { char x; short p:8; short :0; short :0; short p2:8; char y; }; In MS layout the second anon :0 bit-field does _not_ adjust size or alignment of the struct again. The first one does, though.
* bitfields: fix PCC layoutMichael Matz2016-12-151-23/+28
| | | | | Fixes some corner cases in PCC layout. Testcases coming up.
* bitfields: Implement MS compatible layoutMichael Matz2016-12-151-7/+30
| | | | | | | | Bit-fields are layed out differently in visual C, this implements a compatible mode. Checked against Visual C/C++ 2016. Unfortunately the GCC implementation of MS layout (behind -mms-bitfields) actually is different, and hence not compatible with MS in all cases :-/
* Fix struct layout some moreMichael Matz2016-12-152-40/+199
| | | | | | Anonymous sub-sub-members weren't handled correctly. Bit-fields neither: this implements PCC layout for now. It temporarily disables MS-compatible bit-field layout.
* Split off record layoutingMichael Matz2016-12-152-82/+114
| | | | | | | | | | | Such struct decl: struct S { char a; int i;} __attribute__((packed)); should be accepted and cause S to be five bytes long (i.e. the packed attribute should matter). So we can't layout the members during parsing already. Split off the offset and alignment calculation for this.
* x86-asm: Fix segfaultMichael Matz2016-12-151-1/+1
| | | | We need to access cur_text_section, not text_section.
* Fix 64bit enums and switch casesMichael Matz2016-12-153-41/+196
| | | | | | | See testcases. We now support 64bit case constants. At the same time also 64bit enum constants on L64 platforms (otherwise the Sym struct isn't large enough for now). The testcase also checks for various cases where sign/zero extension was confused.
* tccpp: Fix token pastingMichael Matz2016-12-154-7/+29
| | | | | | | | | See testcase. We must always paste tokens (at least if not currently substing a normal argument, which is a speed optimization only now) but at the same time must not regard a ## token coming from argument expansion as the token-paste operator, nor if we constructed a ## token due to pasting itself (that was already checked by pp/01.c).
* libtcc1: Don't use stdlib functionsMichael Matz2016-12-151-3/+0
| | | | | | | | | | | libtcc1 is the compiler support library and therefore needs to function in a freestanding environment. In particular it can't just use fprintf or stderr, which it was on x86-64 (but only when compiled by GCC). The tight integration between libtcc1 and tcc itself makes it impossible to ever reach that case so the abort() there is enough. abort() is strictly speaking also not available in a freestanding environment, but it often is nevertheless.
* Fix miscompile with dead switchesMichael Matz2016-12-152-7/+60
| | | | | | | | In certain very specific situations (involving switches with asms inside dead statement expressions) we could generate invalid code (clobbering the buffer so much that we generated invalid instructions). Don't emit the decision table if the switch itself is dead.
* Handle multiple -O optionsMichael Matz2016-12-151-3/+5
| | | | the last one wins, i.e. "-O2 -O0" does _not_ set __OPTIMIZ__.
* build: Respect CPPFLAGS overrideMichael Matz2016-12-151-0/+2
| | | | so that e.g. make CPPFLAGS=-DSOMETHING works.
* 64bit: Fix addends > 32 bitsMichael Matz2016-12-153-2/+27
| | | | | | If a symbolic reference is offsetted by a constant > 32bit the backends can't deal with that, so don't construct such values.
* x86-64-asm: Accept high register in clobbersMichael Matz2016-12-153-18/+53
| | | | | | | The callee saved registers (among them r12-r15) really need saving/restoring if mentioned in asm clobbers, even if TCC itself doesn't use them. E.g. the linux kernel relies on that in its switch_to() implementation.
* Fix initializing members multiple timesMichael Matz2016-12-155-0/+73
| | | | | | | When intializing members where the initializer needs relocations and the member is initialized multiple times we can't allow that to lead to multiple relocations to the same place. The last one must win.
* Support local register variablesMichael Matz2016-12-154-6/+58
| | | | | | | | | Similar to GCC a local asm register variable enforces the use of a specified register in asm operands (and doesn't otherwise matter). Works only if the variable is directly mentioned as operand. For that we now generally store a backpointer from an SValue to a Sym when the SValue was the result of unary() parsing a symbol identifier.
* Fix const folding of 64bit pointer constantsMichael Matz2016-12-152-2/+8
| | | | See testcase.
* x86-asm: Correct register size for pointer opsMichael Matz2016-12-152-1/+10
| | | | | A pointer is 64 bit as well, so it needs a full register for register operands.
* struct-init: Copy relocs for compound literalsMichael Matz2016-12-152-0/+55
| | | | | When copying the content of compound literals we must include relocations as well.
* x86_64-asm: fix copy-out registersMichael Matz2016-12-152-1/+11
| | | | | | If the destination is an indirect pointer access (which ends up as VT_LLOCAL) the intermediate pointer must be loaded as VT_PTR, not as whatever the pointed to type is.
* x86_64: Add -mno-sse optionMichael Matz2016-12-153-4/+29
| | | | | This disables generation of any SSE instructions (in particular in stdarg function prologues). Necessary for kernel compiles.
* x86-64: relocation addend is 64bitMichael Matz2016-12-153-6/+6
| | | | | | | | Some routines were using the wrong type (int) in passing addends, truncating it. This matters when bit 31 isn't set and the high 32 bits are set: the truncation would make it unsigned where in reality it's signed (happen e.g. on the x86-64 with it's load address at top-2GB).
* x86-64: Prefer 32S relocationsMichael Matz2016-12-152-2/+2
| | | | | | | | | | | | | | | | This target has _32 and _32S relocs (the latter being for signed 32 bit entities). All instruction displacements have to use the 32S variants. Normal references like .long s normally would use the _32 variant. For normal executables this doesn't matter. For shared libraries neither (which use PC-relative relocs). But it matters for things like the kernel that are linked to high addresses (signed ones). There the GNU linker would error out on overflow for the _32 variant. To keep life simple we simply switch from _32 to _32S altogether. Strictly speaking it's still wrong, but in practice using _32 is more often wrong than using _32S ;)
* opt: Don't emit inline functions from dead codeMichael Matz2016-12-152-1/+9
| | | | | Inside dead code don't regard inline functions as being referenced.
* Handle __builtin_extract_return_addrMichael Matz2016-12-152-0/+5
| | | | | Our architectures don't need anything special for this builtin, just pass through the argument.
* opt: constprop also 'cond && 0'Michael Matz2016-12-152-62/+113
| | | | | | We didn't handle constants in logical expressions when they weren't the first operand. Some reordering in the loop structure is enough to handle them.
* opt: Make break and goto not fallthroughMichael Matz2016-12-152-2/+68
| | | | | As we can optimize dead code a bit already it's fitting to disable code emission after break and goto.
* opt: Start optimizing dead code a bitMichael Matz2016-12-154-2/+182
| | | | | | | If a condition is always zero/non-zero we can omit the then or else code. This is complicated a bit by having to deal with labels that might make such code reachable without us yet knowing during parsing.
* Revert "Reject jumping inside stmtexprs"Michael Matz2016-12-151-7/+1
| | | | | | | | | | | | | Not fully thought out. You can't jump inside stmt exprs, but you can jump out of them. So there's a difference between undefined but declared labels at the end of stmt exprs and those defined inside. Additionally it should also be checked if a label defined inside a stmt expr was tentatively created as declared from outside. I'm not prepared doing that right now, so simply revert. This reverts commit 9160e4cab9147d77840cc44a285031fdb4640cf9.
* Factor out const condition detectionMichael Matz2016-12-151-10/+22
| | | | Creating condition_3way for this.
* Reject jumping inside stmtexprsMichael Matz2016-12-151-1/+7
| | | | | | | | | | | | One can't jump into statement expressions from outside them, like the following: int i = ({ label: foo(); 42; }); goto label; We reject this by making the labels simply not available outside (GCC has a nicer error message about jumping into a statement expression).
* Fix more nocode_wanted jump problemsMichael Matz2016-12-153-4/+46
| | | | | | | In statement expression we really mustn't emit backward jumps under nocode_wanted (they will form infinte loops as no expressions are evaluated). Do-while and explicit loop with gotos weren't handled.
* Fix aliases on 64 bitMichael Matz2016-12-152-2/+3
| | | | Use correct width ELF structure.
* Fix sizeof(char[a])Michael Matz2016-12-152-12/+25
| | | | | The sizes of VLAs need to be evaluated even inside sizeof, i.e. when nocode_wanted is set.
* Fix __builtin_constant_p(1000/x)Michael Matz2016-12-152-0/+27
| | | | | was incorrectly treated as constant because the vpop removed all traces of non-constness.
* tccasm: Support refs to anon symbols from asmMichael Matz2016-12-154-13/+52
| | | | | | | This happens when e.g. string constants (or other static data) are passed as operands to inline asm as immediates. The produced symbol ref wouldn't be found. So tighten the connection between C and asm-local symbol table even more.
* tccasm: Don't ignore # in preprocessor directivesMichael Matz2016-12-154-25/+49
| | | | | | | Our preprocessor throws away # line-comments in asm mode. It did so also inside preprocessor directives, thereby removing stringification. Parse defines in non-asm mode (but retain '.' as identifier character inside macro definitions).
* x86-asm: Accept all 32bit immediatesMichael Matz2016-12-152-1/+3
| | | | | In particular don't care if they're signed or unsigned, they're all acceptable as immediates.
* Fix enum bitfields passed to stdarg functionsMichael Matz2016-12-152-0/+6
| | | | | VT_ENUM types use the .ref member and can be VT_BITFIELD, so we need to copy it as well. Simply do it always.
* Addresses of non-weak symbols are non-zeroMichael Matz2016-12-152-1/+13
| | | | Use this fact in some foldings of comparisons. See testcase.
* Fix access-after-free with statement expressionsMichael Matz2016-12-154-29/+76
| | | | | | | | | | | | The return value of statement expressions might refer to local symbols, so those can't be popped. The old error message always was just a band-aid, and since disabling it for pointer types it wasn't effective anyway. It also never considered that also the vtop->sym member might have referred to such symbols (see the testcase with the local static, that used to segfault). For fixing this (can be seen better with valgrind and SYM_DEBUG) simply leave local symbols of stmt exprs on the stack.
* tccpp: Allow computed include like 42.hMichael Matz2016-12-153-29/+50
| | | | | | The include directive needs to be parsed as pp-tokens, not as token (i.e. no conversion to TOK_STR or TOK_NUM). Also fix parsing computed includes using quoted strings.
* x86-asm: Correctly infer register size for boolsMichael Matz2016-12-152-1/+12
| | | | | | Register operands of type _Bool weren't correctly getting the 8-bit sized registers (but rather used the default 32-bit ones).
* x86-64-asm: Implement cmpxchg16bMichael Matz2016-12-152-0/+6
|