Artifacts Associated With Ticket 2184717fffffffff
Ticket change [3f9364b0dc] (rid 121482) by dgp on 2008-10-21 15:28:14:
- assignee initialized to: "hobbs"
- cmimetype initialized to: "text/plain"
- comment initialized to:
Testing memory hygiene in a program that embeds Tcl on an x86_64 system with ElectricFence, we encountered panics in the Tcl library. The problem boils down to this. Tcl's Tcl_Alloc() routine (and the ckalloc() form) is documented to return a pointer aligned for any purpose. Some of the Tcl source code is written assuming this to be true. Unfortunately, when malloc() returns a pointer that is misaligned for some purposes (notably for holding a pointer value), the TclpAlloc() implementation in tclThreadAlloc.c propagates that misalignment up to the pointer returned by ckalloc() leading to panics in the code that assumes this cannot happen. Misaligned malloc() returns is one of the hazards introduced by ElectricFence testing. Since Tcl_Alloc() is documented to return an aligned pointer, and it cannot always be assumed that malloc() will cooperate, it would make Tcl more robust, and more useful for testing in partnership with ElectricFence, if the allocator in tclThreadAlloc.c included safeguards to prevent misalignment from bubbling up from below.
- foundin initialized to: "obsolete: 8.5.5"
- is_private initialized to: "0"
- priority initialized to: "5 Medium"
- resolution initialized to: "None"
- status initialized to: "Open"
- submitter initialized to: "dgp"
- subsystem initialized to: "41. Memory Allocation"
- title initialized to: "unaligned malloc() -> Tcl panic"
- type initialized to: "Bug"
Ticket change [76a068a898] (rid 105619) by cc_benny on 2008-10-24 22:02:19:
- icomment:
Are you sure you have the right culprit here? What you describe sounds like a bug in ElectricFence or maybe somewhere else. > Tcl's Tcl_Alloc() routine (and the ckalloc() form) is > documented to return a pointer aligned for any purpose. This is the same guarantee that malloc gives. I checked the C standard as well as my local man pages (on Mac OS X) about this. See also <http://www.opengroup.org/onlinepubs/009695399/functions/malloc.html>. > Unfortunately, when malloc() returns a pointer that is > misaligned for some purposes (notably for holding a > pointer value) That implementation of malloc would be broken. Note that there are no simple functions in standard C that can be used to ensure alignment and that a portable implementation to do this is non-trivial (from the POV of the rather generic C standard at least). A malloc that does not ensure alignment would be unreasonable or even useless.
- login: "cc_benny"
- mimetype: "text/plain"
- username: "cc_benny"
- icomment:
Ticket change [5f004db29c] (rid 115735) by dgp on 2008-10-24 22:11:47:
- icomment:
By that standard, yes, ElectricFence is "broken". However, EF is a useful tool, and this aspect of its brokenness is essential to how it functions. If Tcl can be revised with reasonable effort and without significant negative impact so that it tolerates this kind of brokenness, that would be desirable.
- login: "dgp"
- mimetype: "text/plain"
- username: "dgp"
- icomment:
Ticket change [2d154227e7] (rid 119019) by dkf on 2008-10-24 23:48:43:
- icomment:
Sounds to me like EF is broken x86_64. A shame. Report it to the EF people and move on. (If their response is "we don't support EF on that architecture" then we'll just have to live without EF on x86_64.)
- login: "dkf"
- mimetype: "text/plain"
- username: "dkf"
- icomment:
Ticket change [114096f6e2] (rid 95108) by cc_benny on 2008-10-25 00:10:34:
- icomment:
> However, EF is a useful tool, I'm sure it is. I haven't used it before, but I have heard about it. > and this aspect of its brokenness is essential to how it > functions. I just downloaded ElectricFence to understand what you mean. From the manual page it seems that this exact issue is addressed by its configuration parameter EF_ALIGNMENT and the section in the manual "WORD-ALIGNMENT AND OVERRUN DETECTION". To counteract the problem posed in that section, Tcl_Alloc could round up every allocation to a multiple of sizeof(void*) before calling malloc. OTOH setting EF_ALIGNMENT=8 seems to have the exact same effect (on a 64 bit system) without requiring changes to Tcl. That seems to me to be the better option. Or did you have some other change in mind that is not just equivalent to EF_ALIGNMENT=8?
- login: "cc_benny"
- mimetype: "text/plain"
- username: "cc_benny"
- icomment:
Ticket change [19c1d1f44e] (rid 140215) by dgp on 2014-10-09 16:29:13:
- assignee changed to: "dgp"
- closedate changed to: "2456940.18696495"
- closer changed to: "dgp"
- comment changed to:
Testing memory hygiene in a program that embeds Tcl on an x86_64 system with ElectricFence, we encountered panics in the Tcl library. The problem boils down to this. Tcl's Tcl_Alloc() routine (and the ckalloc() form) is documented to return a pointer aligned for any purpose. Some of the Tcl source code is written assuming this to be true. Unfortunately, when malloc() returns a pointer that is misaligned for some purposes (notably for holding a pointer value), the TclpAlloc() implementation in tclThreadAlloc.c propagates that misalignment up to the pointer returned by ckalloc() leading to panics in the code that assumes this cannot happen. Misaligned malloc() returns is one of the hazards introduced by ElectricFence testing. Since Tcl_Alloc() is documented to return an aligned pointer, and it cannot always be assumed that malloc() will cooperate, it would make Tcl more robust, and more useful for testing in partnership with ElectricFence, if the allocator in tclThreadAlloc.c included safeguards to prevent misalignment from bubbling up from below.
- login: "dgp"
- mimetype: "text/plain"
- resolution changed to: "Invalid"
- severity changed to: "Minor"
- status changed to: "Closed"