Skip to content
Tcl Source Code History Of Ticket 3166410
Login

History Of Ticket 3166410

Artifacts Associated With Ticket 3166410

  1. Ticket change [5d801afee0] (rid 115472) by starwalker2000 on 2011-01-27 07:39:43:

    1. assignee initialized to: "nobody"
    2. cmimetype initialized to: "text/plain"
    3. comment initialized to:
      I've got "out of stack space" error on AIX when running 32bits-tclsh. No such error of 64bits-tclsh.
      I've traced the code of tcl, I found following problem:
      
      [1] stopped in TclpGetCStackParams at line 1095 in file "/tellin/hjw/tcl8.5.9/unix/../unix/tclUnixInit.c" ($t1)
       1095               tsdPtr->stackBound = (int *) ((char *)tsdPtr->outerVarPtr -
      (dbx) n
      stopped in TclpGetCStackParams at line 1097 in file "/tellin/hjw/tcl8.5.9/unix/../unix/tclUnixInit.c" ($t1)
       1097           } else {
      (dbx) p tsdPtr->outerVarPtr
      0x2ff22460
      (dbx) p stackSize
      2147450878
      (dbx) print tsdPtr->stackBound
      0xaff2a462
      
      According to the message above, the stackSize is a very great value, almost 2G, and tsdPtr->stackBound is a overflowed number. This cause following code returns false:
      #define CheckCStack(iPtr, localIntPtr) \
         ((localIntPtr) > (iPtr)->stackBound)
      (dbx) p &localInt
      0x2ff221a0
      (dbx) p iPtr->stackBound
      0xaff2a462
      
      For 64bits-tclsh, the situation is as follows:
      [1] stopped in TclpGetCStackParams at line 1095 in file "/tellin/hjw/tcl8.5.9-64/unix/../unix/tclUnixInit.c" ($t1)
       1095               tsdPtr->stackBound = (int *) ((char *)tsdPtr->outerVarPtr -
      (dbx) n
      stopped in TclpGetCStackParams at line 1097 in file "/tellin/hjw/tcl8.5.9-64/unix/../unix/tclUnixInit.c" ($t1)
       1097           } else {
      (dbx) print tsdPtr->outerVarPtr
      0x0ffffffffffff140
      (dbx) print stackSize
      4294934528
      (dbx) print tsdPtr->stackBound
      0x0fffffff00007140
      
      The stackSize is amost 4G, but tsdPtr->stackBound is not overflowed. So the CheckCStack returns true.
      
    4. foundin initialized to: "obsolete: 8.5.9"
    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: "starwalker2000"
    10. subsystem initialized to: "None"
    11. title initialized to: ""out of stack space" on AIX"
    12. type initialized to: "Bug"
  2. Ticket change [96f282ba4c] (rid 106424) by dkf on 2011-01-27 16:19:29:

    1. assignee changed to: "dgp"
    2. subsystem changed to: "38. Init - Library - Autoload"
  3. Ticket change [d7319938d8] (rid 123938) by nijtmans on 2011-01-27 18:03:42:

    1. icomment:
      How about changing the lines 1071-1073:
          if (stackSize || (tsdPtr->stackBound &&
          ((stackGrowsDown && (&result < tsdPtr->stackBound)) ||
          (!stackGrowsDown && (&result > tsdPtr->stackBound))))) {
      to:
          if (stackSize || (tsdPtr->stackBound &&
          ((stackGrowsDown && ((&result - tsdPtr->stackBound) < 0)) ||
          (!stackGrowsDown && ((&result - tsdPtr->stackBound) > 0))))) {
      
      That should always work, no matter that the stackBound is near the 2G
      bounary. I would fail when the stack grows to more than half the available
      memory, but that seems highly unlikely.
      
      Does that help?
      
      
    2. login: "nijtmans"
    3. mimetype: "text/plain"
    4. username: "nijtmans"
  4. Ticket change [6dfa4630b5] (rid 128798) by nijtmans on 2011-01-27 18:06:28:

    1. icomment:
      And - of course - the same changes in tclBasic.c as well
      
      
    2. login: "nijtmans"
    3. mimetype: "text/plain"
    4. username: "nijtmans"
  5. Ticket change [34f48bbc3e] (rid 106830) by starwalker2000 on 2011-01-27 20:27:12:

    1. icomment:
      These changes work.
      After change tclBasic.c:360 from:
      ((localIntPtr) > (iPtr)->stackBound)
      to
      (((localIntPtr) - (iPtr)->stackBound) > 0)
      
      It makes the ((localIntPtr) - (iPtr)->stackBound) becomes a positive value. But I've no idea will it cause other problem on other machines.
      However, I still think the value of (iPtr)->stackBound is incorrect.
      
      stopped in TclInterpReady at line 3474 in file "/tellin/hjw/tcl8.5.9/unix/../generic/tclBasic.c" ($t1)
       3474               && CheckCStack(iPtr, &localInt)) {
      (dbx) print &localInt
      0x2ff22150
      (dbx) print iPtr->stackBound
      0xaff2a462
      (dbx) print &localInt - iPtr->stackBound
      0x7fff7cee
      
      
      
    2. login: "starwalker2000"
    3. mimetype: "text/plain"
    4. username: "starwalker2000"
  6. Ticket change [6c6d37a7ca] (rid 128506) by nijtmans on 2011-01-28 15:06:06:

    1. assignee changed to: "nijtmans"
    2. icomment:
      My guess is that on AIX there is a bug in pointer comparison, such that all pointers above the 2G are considered smaller than pointer below 2G. So, whenever two pointers are compared, one below and the other above the 2G border, the result is not correct. I see 2 possible solutions to this:
      
      - First substracting the two pointers results in a ptr_diff type,
        which is always signed. Then we can compare this to 0, and
        as long as no-one pushed more than 2G on the stack the
        result will be as expected. Well, 2G is an incredable
        amount, I don't think there is any machine with a total
        stack size as big a half the available memory.
      - Another solution would be to cast the pointers to
        (size_t) before the comparison, so:
      
             ((size_t)(localIntPtr) > (size_t)(iPtr)->stackBound)
      
        Then we simply correct AIX's comparison 'bug', but it
        looks more ugly ;-)
      
      I would prefer the first possibility, but someone might
      try to convince me otherwise. Anyone?
      
      
    3. login: "nijtmans"
    4. mimetype: "text/plain"
    5. username: "nijtmans"
  7. Ticket change [14237cb592] (rid 124340) by dkf on 2011-01-28 22:53:50:

    1. icomment:
      Ugly's OK. It's conceptually ugly anyway.
      
      
    2. login: "dkf"
    3. mimetype: "text/plain"
    4. username: "dkf"
  8. Ticket change [807c5c3cec] (rid 116879) by dkf on 2011-01-28 22:55:12:

    1. icomment:
      But don't make changes without testing on several platforms (minimally including a normal x86 Unix with gcc, Windows with MSVC, and AIX because it is known to have an issue).
      
      
    2. login: "dkf"
    3. mimetype: "text/plain"
    4. username: "dkf"
  9. Ticket change [1b35d2110e] (rid 123105) by starwalker2000 on 2011-01-30 21:31:17:

    1. icomment:
      I still think it's the problem of calculating iPtr->stackBound.
      Obviously, 0x2ff221a0 minus 2147450878 is a nagtive value for 32-bits integer.
      
      
    2. login: "starwalker2000"
    3. mimetype: "text/plain"
    4. username: "starwalker2000"
  10. Ticket change [5bddd8713e] (rid 118405) by nijtmans on 2011-01-31 03:08:44:

    1. icomment:
      Yes, something is very strange here: A stack size of
      2147450878 (0x7FFF7FFE), that's very big! So
      maybe the stacksize calculation is simply wrong
      for AIX. Then that should be corrected instead of
      making the code uglier... I'm hesitating
      
      
    2. login: "nijtmans"
    3. mimetype: "text/plain"
    4. username: "nijtmans"
  11. Ticket change [59c0d28f69] (rid 118022) by mistachkin on 2011-01-31 03:26:28:

    1. icomment:
      I'm trying to get access to an AIX box to help with this issue.  I have a few theories of my own I would like to test.
      
      
    2. login: "mistachkin"
    3. mimetype: "text/plain"
    4. username: "mistachkin"
  12. Ticket change [154747b976] (rid 124543) by starwalker2000 on 2011-01-31 08:47:34:

    1. icomment:
      I think the stack size is correct. The stack size on AIX can be set by the file /etc/security/limits which set stack to -1 and means "unlimited".
      
      The limitations are as follows:
      # ulimit -a
      time(seconds)        unlimited
      file(blocks)         unlimited
      data(kbytes)         unlimited
      stack(kbytes)        4194304
      memory(kbytes)       unlimited
      coredump(blocks)     2097151
      nofiles(descriptors) 2000
      
      For 32-bits program, the stack size is nearly 2G. For 64-bits program, the stack size is nearly 4G.
      
      If I change the stack limitation to a smaller number, for example 65536, which makes the stack size to 32M. The 32-bits tclsh won't core dump due to there is no stack bound problem.
      
      
    2. login: "starwalker2000"
    3. mimetype: "text/plain"
    4. username: "starwalker2000"
  13. Ticket change [15e73d5d7c] (rid 124641) by nijtmans on 2011-01-31 14:32:32:

    1. icomment:
      
      
      File Added - 400301: 3166410.patch
      
      
      
    2. login: "nijtmans"
    3. mimetype: "text/plain"
    4. username: "nijtmans"
  14. Ticket change [5c8189e98b] (rid 115313) by nijtmans on 2011-01-31 14:34:40:

    1. icomment:
      Thanks! so how about the attached patch? No matter that we have a very big stack space, calculating
      the border should never overflow! If it does, it means that we already occupied a part of the
      stack, so the real stack size is lower. Here is a patch trying to accomplish that.
      
      Does this help?
      
      
    2. login: "nijtmans"
    3. mimetype: "text/plain"
    4. username: "nijtmans"
  15. Ticket change [74be68cc06] (rid 105260) by nijtmans on 2011-01-31 14:52:08:

    1. icomment:
      
      
      File Deleted - 400301: 
      
      
      
    2. login: "nijtmans"
    3. mimetype: "text/plain"
    4. username: "nijtmans"
  16. Add attachment "3166410.patch" [4869b18383] (rid 99878) by nijtmans on 2011-01-31 14:52:30.

  17. Ticket change [87da777238] (rid 131771) by nijtmans on 2011-01-31 14:52:30:

    1. icomment:
      
      
      File Added - 400303: 3166410.patch
      
      
      
    2. login: "nijtmans"
    3. mimetype: "text/plain"
    4. username: "nijtmans"
  18. Ticket change [d24093dfcc] (rid 113506) by starwalker2000 on 2011-02-09 11:43:37:

    1. icomment:
      This patch (3166410.patch) works。
      
      
    2. login: "starwalker2000"
    3. mimetype: "text/plain"
    4. username: "starwalker2000"
  19. Ticket change [1365a803df] (rid 124212) by nijtmans on 2011-03-08 05:31:04:

    1. closedate changed to: "2011-03-07T22:31:04"
    2. closer changed to: "nijtmans"
    3. icomment:
      
      
      allow_comments - 1
      
      Fixed on core-8-5-branch. Not applicable to trunk and 8.4
      
      
    4. login: "nijtmans"
    5. mimetype: "text/plain"
    6. resolution changed to: "Fixed"
    7. status changed to: "Closed"
    8. username: "nijtmans"