Navigation Menu

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

Evaluating the size of a structure is wrongly done #4763

Closed
p6rt opened this issue Nov 18, 2015 · 8 comments
Closed

Evaluating the size of a structure is wrongly done #4763

p6rt opened this issue Nov 18, 2015 · 8 comments

Comments

@p6rt
Copy link

p6rt commented Nov 18, 2015

Migrated from rt.perl.org#126675 (status was 'resolved')

Searchable as RT126675$

@p6rt
Copy link
Author

p6rt commented Nov 18, 2015

From @Skarsnik

While writing a binding for Gumbo (A c99 lib to parse html) I came across an error on amd64 bits. One of the mapped struct has his size evaluated wrongly by nativesizeof (different than a call from sizeof see​: http://pastebin.com/FVagmG6T). It provokes random segfault because of that. It seem NC try to align the struct and fail. (8 bytes are added)

After isolating on a test file the struct (see attached file) and tracking some value on
https://github.com/MoarVM/MoarVM/blob/master/src/6model/reprs/CStruct.c#L110

I appear that after evaluating the size of the 2 last attributes (12 bytes each one)
https://github.com/MoarVM/MoarVM/blob/master/src/6model/reprs/CStruct.c#L256
realign the size and adding 2 time 4 bytes, ending with the wrong size of 104 bytes instead of 96.
I don't know if the align for the struct that is 12 bytes sized should be 4 bytes (and not ALIGNOF(void*) that is 8 for 64bits) or just the pointed (L256) adjustment is wrong

@p6rt
Copy link
Author

p6rt commented Nov 18, 2015

From @Skarsnik

testwrongsize.p6

@p6rt
Copy link
Author

p6rt commented Nov 18, 2015

From @Skarsnik

Le Mer 18 Nov 2015 07​:53​:46, scolinet@​gmail.com a écrit :

While writing a binding for Gumbo (A c99 lib to parse html) I came
across an error on amd64 bits. One of the mapped struct has his size
evaluated wrongly by nativesizeof (different than a call from sizeof
see​: http://pastebin.com/FVagmG6T). It provokes random segfault
because of that. It seem NC try to align the struct and fail. (8 bytes
are added)

After isolating on a test file the struct (see attached file) and
tracking some value on
https://github.com/MoarVM/MoarVM/blob/master/src/6model/reprs/CStruct.c#L110

I appear that after evaluating the size of the 2 last attributes (12
bytes each one)
https://github.com/MoarVM/MoarVM/blob/master/src/6model/reprs/CStruct.c#L256
realign the size and adding 2 time 4 bytes, ending with the wrong size
of 104 bytes instead of 96.
I don't know if the align for the struct that is 12 bytes sized should
be 4 bytes (and not ALIGNOF(void*) that is 8 for 64bits) or just the
pointed (L256) adjustment is wrong

The pastbin link is http://pastebin.com/FVagmG6T the ) get in the link

@p6rt
Copy link
Author

p6rt commented Nov 18, 2015

From @FROGGS

I can confirm that the alignment is wrong.

To prove, I created this repo​: https://github.com/FROGGS/p6-Gumbo
Running `perl6 t` gives​:
~/dev/gumbo$ perl6 t/00-structure-sizes.t
1..19
ok 1 - sizeof(size_t)
ok 2 - sizeof(GumboStringPiece)
ok 3 - sizeof(GumboSourcePosition)
ok 4 - sizeof(GumboVector)
ok 5 - sizeof(GumboTag)
ok 6 - sizeof(GumboNamespaceEnum)
ok 7 - sizeof(MyGumboTest)
not ok 8 - sizeof(GumboElement)

# Failed test 'sizeof(GumboElement)'
# at t/00-structure-sizes.t line 85
# expected​: '96'
# got​: '104'

Which hints at the last two attributes of the GumboElement structure, as the ticket already pointed out.

@p6rt
Copy link
Author

p6rt commented Nov 18, 2015

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Nov 18, 2015

From @FROGGS

The fix for this misalignment is​: MoarVM/MoarVM@7b382acd61
Test got added here​: rakudo/rakudo@deeec10a2e

Closing ticket as resolved.

1 similar comment
@p6rt
Copy link
Author

p6rt commented Nov 18, 2015

From @FROGGS

The fix for this misalignment is​: MoarVM/MoarVM@7b382acd61
Test got added here​: rakudo/rakudo@deeec10a2e

Closing ticket as resolved.

@p6rt p6rt closed this as completed Nov 18, 2015
@p6rt
Copy link
Author

p6rt commented Nov 18, 2015

@FROGGS - Status changed from 'open' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant