This is the mail archive of the mailing list for the newlib project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Semihosting fix


Code was introduced in commit 8d98f956cc398d086794e19051c3380d599022da
that breaks semihosting for ARM Cortex targets running in many

To implement semihosting, ARM bkpt or svc instructions are used to
provide system calls implementing more-or-less standard functions. One
of these system calls (HeapInfo) can be used to provide dynamic heap
and stack information to the user application.

More often than not, dynamic stack and heap information is not
available, and the system call generally provides null values in this
case. Segger GDBServer and OpenOCD 0.9.9 are examples of this.

The standard C library behavior when heap information is not available
is to permit the heap to grow (each time sbrk is called) until the
heap runs into the stack pointer. This is how sbrk worked before
commit 8d98f956cc398d086794e19051c3380d599022da. The current behavior,
when heap information is missing, is that crt0.S code writes the null
value into the __heap_limit variable, causing sbrk to believe that
the heap is full, causing most newlib calls to fail (like printf).

Here is a two-instruction fix that checks that the heap limit provided
by HeapInfo is not zero before writing it to __heap_limit. No sane
implementation would use 0 as the upper value of the heap, so this
fix, which has been tested, should not break anything. Commit
8d98f956cc398d086794e19051c3380d599022da, however, breaks all Cortex M
semihosting running on the two debuggers mentioned above, and probably

Could you please consider inclusion of the following patch?

Thank you,

David Hoover

diff --git a/libgloss/arm/crt0.S b/libgloss/arm/crt0.S
index 7c662f9..b459e12 100644
--- a/libgloss/arm/crt0.S
+++ b/libgloss/arm/crt0.S
@@ -125,9 +125,11 @@

        /* Set __heap_limit.  */
        ldr     r1, [r0, #4]
+       cmp     r1, #0
+       beq     .LC33
        ldr     r2, =__heap_limit
        str     r1, [r2]
        ldr     r1, [r0, #0]
        cmp     r1, #0
        bne     .LC32

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]