tccelf: fix int(0x8000_0000) overflow in shf_private constant#7
Open
quaesitor-scientiam wants to merge 2 commits intofelipensp:stablefrom
Open
tccelf: fix int(0x8000_0000) overflow in shf_private constant#7quaesitor-scientiam wants to merge 2 commits intofelipensp:stablefrom
quaesitor-scientiam wants to merge 2 commits intofelipensp:stablefrom
Conversation
`const shf_private = int(0x8000_0000)` overflows V's `int` type
(max 2147483647). V currently emits a warning for this and will make
it a hard error in a future release. When the overflow occurs, it
produces broken C that the TCC backend rejects with:
cc: error: invalid operand types for binary operation
causing the vtcc build to fail with `V panic: result not set (failed)`.
Fix: replace with `-2147483648`, which is INT_MIN — the same bit
pattern as `0x8000_0000` in two's complement signed representation.
All existing bitwise operations on this constant are unaffected, and
the type stays `int` so no downstream type changes are required.
Fixes: vlang/v#26853
quaesitor-scientiam
pushed a commit
to quaesitor-scientiam/v
that referenced
this pull request
Apr 12, 2026
The previous patch (in vlang#26858) changed `int(0x8000_0000)` → `u32(0x8000_0000)`, which fixed the overflow warning but introduced a new type error: failed src/tccelf.v:49:65: error: `(shf_private | shf_dynsym)` (no value) used as value in argument 4 to `new_symtab` Root cause: `shf_dynsym` is still `int` and `new_symtab` takes `sh_flags int`; V cannot OR `u32 | int` and implicitly pass the result as `int`. Changing to `u32` throughout cascades into 20+ sites across tccelf.v and struct Section. Correct workaround: use `-2147483648` (INT_MIN) instead — the identical bit pattern as `0x8000_0000` in two's complement, with type `int`. No downstream type changes needed. A proper fix has been filed upstream at felipensp/vtcc#7. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 task
Follow-up to the shf_private fix: `int(0x4000_0000)` does not overflow (1073741824 < 2147483647) but the explicit `int()` cast is redundant and misleading alongside the now-fixed shf_private. Remove it so both flag constants read consistently. Addresses the second half of felipensp#6.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
src/tccelf.vhas two constants using explicitint()casts on hex literals:shf_privateoverflows V'sint. V currently emits a warning and will make this a hard error soon. The overflow causes broken generated C that TCC rejects:This makes vtcc fail to build in the vlang/v CI with
V panic: result not set (failed). Tracked at vlang/v#26853.Fix
Two commits:
shf_private: replaceint(0x8000_0000)with-2147483648(INT_MIN — same bit pattern in two's complement, type staysint, no cascading changes needed innew_section/new_symtab/struct Section.sh_flags)shf_dynsym: remove the redundantint()cast — the value 0x4000_0000 = 1073741824 fitsintfine, the cast is just noiseFixes #6