Uploaded image for project: 'Embedded Software & Tools'
  1. Embedded Software & Tools
  2. EXT_EP-8827

Compiler erroneously speculates indexed load from the stack

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: High High
    • Code Generation Tools
    • CODEGEN-4419
    • Hide
      C2000_16.9.0.LTS
      ARM_18.1.0.LTS
      MSP430_18.1.0.LTS
      C6000_8.2.0
      ARM_16.9.0.LTS
      C2000_18.1.0.LTS
      C6000_8.1.0B1
      C6000_7.4.0B1
      PRU_2.2.0
      MSP430_16.9.0.LTS
      Show
      C2000_16.9.0.LTS ARM_18.1.0.LTS MSP430_18.1.0.LTS C6000_8.2.0 ARM_16.9.0.LTS C2000_18.1.0.LTS C6000_8.1.0B1 C6000_7.4.0B1 PRU_2.2.0 MSP430_16.9.0.LTS
    • Hide
      MSP430_16.9.8.LTS
      C6000_8.2.3
      ARM_18.1.2.LTS
      C2000_16.9.8.LTS
      C2000_18.1.2.LTS
      C6000_8.1.7
      PRU_2.3.0
      ARM_16.9.8.LTS
      C6000_7.4.24
      MSP430_18.1.2.LTS
      Show
      MSP430_16.9.8.LTS C6000_8.2.3 ARM_18.1.2.LTS C2000_16.9.8.LTS C2000_18.1.2.LTS C6000_8.1.7 PRU_2.3.0 ARM_16.9.8.LTS C6000_7.4.24 MSP430_18.1.2.LTS
    • Hide
      Modify the source code of the offending function to make local variables "volatile." There's no obvious way to pre-determine that a function will suffer from this bug; you just have to wait for the bug to happen, look at the line number of the offending instruction (which will always be a load with indexed addressing with base register SP), and go to the function at that line number. Make every local variable in that function "volatile." If it's a C++ function, you may need to make the function "volatile."
      Show
      Modify the source code of the offending function to make local variables "volatile." There's no obvious way to pre-determine that a function will suffer from this bug; you just have to wait for the bug to happen, look at the line number of the offending instruction (which will always be a load with indexed addressing with base register SP), and go to the function at that line number. Make every local variable in that function "volatile." If it's a C++ function, you may need to make the function "volatile."
    • Hide
      The compiler moves instructions from one block to another to increase parallelism. Usually this is done by predicating (adding a condition to) every instruction that is moved above a branch. However, in some cases, the compiler will "speculate" the instruction, which means removing the condition entirely. This is done when the instruction's side-effects are judged to be safe, such as load of a local variable. In the case that the instruction's condition would have been false, this load will be useless, but at least it will be safe, because the stack pointer (SP) is at a legal location, and there won't be a memory fault. However, when a local variable's value is read with an indexed expression, the index register is not necessarily speculated exactly when the load is, so the index register may have a garbage value. In this test case, the load was speculated, but the index register definition wasn't, so in the false branch, the computed address was garbage, and we would read a random memory address, causing a memory fault. (Even though SP was perfectly valid, the index register was garbage, so SP+index might point anywhere in memory.)
      Show
      The compiler moves instructions from one block to another to increase parallelism. Usually this is done by predicating (adding a condition to) every instruction that is moved above a branch. However, in some cases, the compiler will "speculate" the instruction, which means removing the condition entirely. This is done when the instruction's side-effects are judged to be safe, such as load of a local variable. In the case that the instruction's condition would have been false, this load will be useless, but at least it will be safe, because the stack pointer (SP) is at a legal location, and there won't be a memory fault. However, when a local variable's value is read with an indexed expression, the index register is not necessarily speculated exactly when the load is, so the index register may have a garbage value. In this test case, the load was speculated, but the index register definition wasn't, so in the false branch, the computed address was garbage, and we would read a random memory address, causing a memory fault. (Even though SP was perfectly valid, the index register was garbage, so SP+index might point anywhere in memory.)

      Compiler erroneously speculates indexed load from the stack

            syncuser TI User
            syncuser TI User
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: