Skip to content
Tcl Source Code History Of Ticket 218471
Login

History Of Ticket 218471

Artifacts Associated With Ticket 218471

  1. Ticket change [3f9364b0dc] (rid 121482) by dgp on 2008-10-21 15:28:14:

    1. assignee initialized to: "hobbs"
    2. cmimetype initialized to: "text/plain"
    3. 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.
      
    4. foundin initialized to: "obsolete: 8.5.5"
    5. is_private initialized to: "0"
    6. priority initialized to: "5 Medium"
    7. resolution initialized to: "None"
    8. status initialized to: "Open"
    9. submitter initialized to: "dgp"
    10. subsystem initialized to: "41. Memory Allocation"
    11. title initialized to: "unaligned malloc() -> Tcl panic"
    12. type initialized to: "Bug"
  2. Ticket change [76a068a898] (rid 105619) by cc_benny on 2008-10-24 22:02:19:

    1. 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.
      
      
      
    2. login: "cc_benny"
    3. mimetype: "text/plain"
    4. username: "cc_benny"
  3. Ticket change [5f004db29c] (rid 115735) by dgp on 2008-10-24 22:11:47:

    1. 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.
      
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  4. Ticket change [2d154227e7] (rid 119019) by dkf on 2008-10-24 23:48:43:

    1. 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.)
      
      
    2. login: "dkf"
    3. mimetype: "text/plain"
    4. username: "dkf"
  5. Ticket change [114096f6e2] (rid 95108) by cc_benny on 2008-10-25 00:10:34:

    1. 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?
      
      
      
    2. login: "cc_benny"
    3. mimetype: "text/plain"
    4. username: "cc_benny"
  6. Ticket change [19c1d1f44e] (rid 140215) by dgp on 2014-10-09 16:29:13:

    1. assignee changed to: "dgp"
    2. closedate changed to: "2456940.18696495"
    3. closer changed to: "dgp"
    4. 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.
      
    5. login: "dgp"
    6. mimetype: "text/plain"
    7. resolution changed to: "Invalid"
    8. severity changed to: "Minor"
    9. status changed to: "Closed"