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

Native-code "C" interface bug #3528

Closed
vicuna opened this issue Aug 13, 2002 · 2 comments
Closed

Native-code "C" interface bug #3528

vicuna opened this issue Aug 13, 2002 · 2 comments
Labels

Comments

@vicuna
Copy link

vicuna commented Aug 13, 2002

Original bug ID: 1323
Reporter: administrator
Status: closed
Resolution: fixed
Priority: normal
Severity: minor
Category: ~DO NOT USE (was: OCaml general)

Bug description

Hi,

The attached code seems to exhibit a bug in native code compilation in
Objective CAML. I'm using:

Linux 2.4.18, Pentium 3, ocaml versions 3.04, 3.05,
gcc version 2.95.4 20011002 (Debian prerelease)
Linux 2.4.18, StrongARM, ocaml version 3.04
gcc version - don't know offhand, the one in Debian/ARM unstable

The attached program has been stripped down (a bit) to a subset which
still exhibits the bug.

What happens: with "make", "./sim", the program loads an ELF-(ish) file
into memory, then exits. With "make opt", "./sim.opt", the program
exits with a segfault after reading some of the file.

Under valgrind:

==1309== valgrind-1.0.0, a memory error detector for x86 GNU/Linux.
==1309== Copyright (C) 2000-2002, and GNU GPL'd, by Julian Seward.
==1309== Estimated CPU clock rate is 803 MHz
==1309== For more details, rerun with: -v
==1309==
Loading doptest to 0 (C)
Reading program section 0 from offset 568
Writing d8000000 to 10000000
Writing 4b3c0002 to 10000004
==1309== Invalid read of size 4
==1309== at 0x805BD9E: format_caml_exception (in /mnt/chunky/code/ocaml-bug/sim.opt)
==1309== by 0x805BF36: fatal_uncaught_exception (in /mnt/chunky/code/ocaml-bug/sim.opt)
==1309== by 0x805D8A3: caml_main (in /mnt/chunky/code/ocaml-bug/sim.opt)
==1309== by 0x8052729: main (in /mnt/chunky/code/ocaml-bug/sim.opt)
==1309== Address 0x4B3C0000 is not stack'd, malloc'd or free'd
Segmentation fault

If the function call "fread(&val, sizeof(int), 1, f)" is removed from
the file loadelf_c.c, the program seems to work. Likewise if the call
to callback3 is removed.

Thank you for your time, I hope this can be fixed.

Julian


�‹�� 'Y=��í�MoÜÖ‘þ@�±�ª�)ÐSñ"Ë)¹Þ¥¸ÜÕÊ•´Fäͺv,[Få"M›bKqßJ´¸ä–äZ’�£)jäP�H�äØC�@�þ�¹�è±@�m€�ò�rñ!��ÉÌû ¹ôÊJ�KŽÑ7Ð.ùfæÍÌ›73oÈUä¹Ã ¶5Þ^ÐŽ
l»i/-.ÂÕ®/-ÚÅ«�
�œ–ã4�­%Í®×—–�?,�ŸI9Œ“Ô? ÑîŒ�š<ƒï(úK
Q¶ÿ7Ü]:ð�úüuØuÛn5›‡í�}ÑYÌö¿¾�øz£éÀþÛÏß”§áÿ|ÿõN‡Ì´g¶=Oï\Y_ûÙ& j��©mëëÝ_δ ƒ��&�Ý×ß^ët�–#�\Ï#µ»zgíƺ p‚‡2�vãÖmÒæÈh”’šç±Ë¶ífgý�otI[×7.¿¹ LC:Œâ�Ë�F�ö%¥ì.ˆÜ>
�ì
èú!ÞèzGL�Ôžg�rýÚeÄmùÛn�»(ÈÕõ›�;oàÍ2"Ûðµïš@�Ræ
¼AZÄh@²n]ݸùöòŒ�P7Ôu7�–qu‰?ÔuXÀò ÜYp£ëŒcYŸ‰‡¤6 �œÏ¾#öíÃw„ÓÈä���1¥bõ'§?·úË3ç­a soöéˆÌ¯’KdþõŒèé°–NÇ$ó†p¯Ij7nä|
×Á�ŒlÌ‘&›†»�ì�$E4ÌH¤�ÁLÂÝgÊ™L’Å�1oÜ<D�l=boÊ™%>.�m‡•Ë¥�ì@«�,>gñŸÅ³_�Ã,(qE%GñÈŸtYq†�zÁ¸OÉD?ôÍ�¾Ã �­¿è¤þ� ¯ÿy�yÏYÇ�õ¿á,-Éúï´l<ÿ›6?Uý?�8'cx5Iûdí\Òs��]@�0�-�Ãà®�Œi2ÉÌI¼?Mð |n¹Þî��P"?éÁ„�ÅPñ˜|V÷{,$
Ž��=v*TI6ÆŽ%t‡E”ÛïǦ~_'Ä�S‚£�¸÷vܸB$;b®[ï��o»Á áôº;ý˜Ð�ÎÏQ·T!£ Ü&Ã%�‡:|¼aú+hÀ^ì§t/ŠûˆfkrcwØ0ró' —&Knð†�4Œ˜&Œ�rÙu�íR7e\ðWTCÚ��ÙCqý�³Ã˜cT‚ä99�µ�ïµ0…U�›QÔ,í�†Í4öÃmÉ! RÊ�v(L��Ä�?ã*™[‡m�~r>!iDÎ÷‰Ñ1ß çª$_b¦�烆A4¢¡‘Óçbn¤? Æ«��îpû¦èê¸áOR‚³™tÐ9¡‰ !„îû©Q7WÈÂ�Iwâh?¸! =:Jý(|�x� !1uûÆk¸áU8cïÑhä?VI��3‰¸ÿÌÉ�©�N°ho´�Ž‡U’?h˜¢�îL&zÄ$?›]ªH¦©H&æ$ST$E�‡°K�8)Š‰á·í�â¯�í‚ñ…�¹Û'b?¡��ö�.æ×þo¸ƒ1èï¬èÓ÷èç”ÇÃ(Ž¶!î �@·cd bh+¢Á ¡) ÙÖùU?÷˜¨¨viÔãd±“pKw?AµD­’Ín÷zo³{Û”VàÊîàÊî¬J^ŒŠä�.´›&ãº/t¡ý�Þ+úB…#²¼sŒ))WY�óD�I�wÙø�º‚ÓEH±ù"¢@U1”¦zì-ÈU–Aû,ƒö™c˜?,q�2‹0P¢ÑAÏÇL6Ê<0q’���]Öá†Q)–?*™(N?,?bò�‘7ÓjÀ�QH-0;�´˜R�œ2V)ˆŒì�QB?,.¡ÖMš,‚�"8>?L¸G1MÇqˆµ�°�^ªNë› yÿÇŸ·†Áó×qDÿg·œVþþÇn±çÿFKõ�'�F…Ÿ¦?h8„�]1u6¼,� u==�QhžÆá.dh�¯Ýá(=�å„Á»��e��P܉ÁR¸JØ�ú7¨#^/p�¢qj’5”Z·Ò)ó¯mÈÙ¤v‰Ï6Ie�?7ãÐOMa��Z0 �;ï=—…±Ì|V#‰k!L‡��•�N%?& ��|.¬8€Ó(G�…Á€�l Ý]JšöO[�� ð•�&?›m‰�Øh\lÚ&Y­É¥�›4�õVÂ.xLÀ�VD±Rl‚@´èäö?Ï�aù1�€£Þÿ5šyþ;Möþ¯å4TþŸ�°lßÄLÐ�)�ìq¡\�0e’Qà§Ø|@ä�ymCî�i„Ç8?�À�¤½ØßÞI{A´íCó‘1:6´E†d�X“�nØ'ö~c00� icŠBºÇsÚ0eBÖ-�r�ÒWšdñò? eÅ!†³ØªÔmG cyö�>5ñü—öðÇG4�¹ ¦0Œ°Šõé>ê?º\?ÄZá¦ÞŽx_)ó_Ì7ÉžŸî°bÇœlåå�J™(‚¨?Y ZŠkeÂ9�"�êKA,�ƒ b-“ÁzÛ[¬S³xÃVh5ƒ}âb�¾Ìúp±|!˜/z¥bfú¹Sï3ü�TËøu¬ÝÓ
ÀÕ=?�¾žz¨²Ð‹î¡n²ÇE�Æ�?eß\xêýß1��Gõ�u§^zÿ×Xª/ªú��P¨ÿ:ÝOi�B?–/ÞȲ(’?P {)4шñ›6™Ë_ÔÍ©T{¹ Ðÿá/kÇñøwdþ7ìü÷_g±Žù��‚*ÿO��iúDEÀΤ‡Ï}òí}L·ý�ª�)¾_&7x_’µV챈µˆà[|[µ.Ζ¬°ä?[sýh”Ò$?ã?¦u?Æ�›_ê�6™(?aMC€¯È¸tä}ÑN|‰!Ï�±�Ç ãˆüwØ3Ÿüÿ�§‰ùßhÕUþŸ�ü¾»åÔ©SÙø´vî6ŽÐ÷Mø|$ðM?hg4C›ÑNiH¿xš¡gñë3ñ‘�¤¿r&×ñH|Šô�rú{RÈl?þu�å �"ÆO�±2…ï;‚÷[B>ÚþY?V\¿_ä�kx4…ïG�ݨ�×2;…ïÇE¾×5í¿�Ÿ�ùÎ >æRûp¾�¥õ"߯¦¬·!e °AÀ¨$?Ùk%;ÐÖ¥î–f¥Ðüi�{fÒ¬¾›ºšµ•$š�G| ù’ƒ!^�>=­­^ÿƒöðO�w'�Ï>|�bLøø/šö�®Ÿ¬j�¯¯nhÖŠF®#þ–À�üù—�>™}ò!âÞ�Üo5í�XÞ¿/kgßÿ£¦Ý�2�Ã:¾€ë�ÎÌ>ÔN‘‡Z.ã•Oþ1Ë\�|g?}×þî���þ½�p ®�ü71�õ€¯¯Âç͵Gß6$??’üe�–C’”Æå:uµ4§4.×Ø?—Æ�-?ÿ^�ÿ«¬?�A„GqÐçGa¯Çß)öüp4N{[�)-ã7¦c@bÓ§ñŸ?xƒ?|x¬æüÑ8Í„¤Oýw Æ-ÑxLý�¢î‡�÷—�W�Ÿ�Û¥q»4î–Æ
�(P @?��
�(P @?��
�(P @?��
�(P @?��
�(P `:|�‰Š]M�P��----------------

@vicuna
Copy link
Author

vicuna commented Aug 19, 2002

Comment author: administrator

The attached code seems to exhibit a bug in native code compilation in
Objective CAML.

Indeed: wrong inline code was generated for bigarray assignments. More
precisely, the generated code forgot to put "()" as the result value
of a.{i} <- v, thus causing the callback mechanism to fail when
testing the return value for uncaught exceptions.

This will be fixed in release 3.06. In the meantime, you can work
around the problem by explicitly returning (), as follows:

let writeWord state address value =
let (chunkno, index) = splitaddress address in
match state.memory.(chunkno) with
State.ChunkEmpty ->
let array = newchunk () in
state.memory.(chunkno) <- State.ChunkFull(array);
(* Printf.printf "Writing %lx at %d:%d\n" value chunkno index;)
array.{index} <- value; () (
<============ )
| State.ChunkFull(array) ->
(
Printf.printf "Writing %lx at %d:%d\n" value chunkno index;)
array.{index} <- value; () (
<============ *)
| State.ChunkIO(r, w) -> w index value

Cheers,

  • Xavier Leroy

@vicuna
Copy link
Author

vicuna commented Aug 19, 2002

Comment author: administrator

Fixed 2002-08-19 by XL

@vicuna vicuna closed this as completed Aug 19, 2002
@vicuna vicuna added the bug label Mar 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant