Undefined reference to '__trampoline_setup'

10 posts / 0 new
Last post
salass00
salass00's picture
Offline
Last seen: 1 year 1 month ago
Joined: 2011-02-03 11:27
Undefined reference to '__trampoline_setup'

Anyone know what this means and how it can be fixed?


ppc-amigaos-gcc -Wall -g -O2 -use-dynld -o mpeg2desc mpeg2desc.o compat.o
mpeg2desc.o: In function `process_packets':
/home/salass00/Development/Projects/Shell/dvdauthor/src/mpeg2desc.c:340: undefined reference to `__trampoline_setup'
collect2: ld returned 1 exit status

kas1e
kas1e's picture
Offline
Last seen: 1 year 5 months ago
Joined: 2010-11-30 15:30
Never meet it, but via google

Never meet it, but via google found that link. Maybe can help (at least code have some comment at top, which sounds understanable):

  1. /*
  2.  * The ppc compiler generates calls to __trampoline_setup() when creating
  3.  * trampoline functions on the stack for use with nested functions.
  4.  * This function creates a custom 40-byte trampoline function on the stack
  5.  * which loads r11 with a pointer to the outer function's locals
  6.  * and then jumps to the target nested function.
  7.  */

Maybe just reusing that small ppc code from will be fine ?

salass00
salass00's picture
Offline
Last seen: 1 year 1 month ago
Joined: 2011-02-03 11:27
I got rid of the undefined

I got rid of the undefined reference by compiling and linking mpeg2desc with the following modified trampoline_setup.c file:

  1. /* ===----- trampoline_setup.c - Implement __trampoline_setup -------------===
  2.  *
  3.  * The LLVM Compiler Infrastructure
  4.  *
  5.  * This file is dual licensed under the MIT and the University of Illinois Open
  6.  * Source Licenses. See LICENSE.TXT for details.
  7.  *
  8.  * ===----------------------------------------------------------------------===
  9.  */
  10.  
  11. #include <stdint.h>
  12. #include <stdlib.h>
  13.  
  14. extern void __clear_cache(void* start, void* end);
  15.  
  16. /*
  17.  * The ppc compiler generates calls to __trampoline_setup() when creating
  18.  * trampoline functions on the stack for use with nested functions.
  19.  * This function creates a custom 40-byte trampoline function on the stack
  20.  * which loads r11 with a pointer to the outer function's locals
  21.  * and then jumps to the target nested function.
  22.  */
  23.  
  24. void __trampoline_setup(uint32_t* trampOnStack, int trampSizeAllocated,
  25. const void* realFunc, void* localsPtr)
  26. {
  27. /* should never happen, but if compiler did not allocate */
  28. /* enough space on stack for the trampoline, abort */
  29. if ( trampSizeAllocated < 40 )
  30. abort();
  31.  
  32. /* create trampoline */
  33. trampOnStack[0] = 0x7c0802a6; /* mflr r0 */
  34. trampOnStack[1] = 0x4800000d; /* bl Lbase */
  35. trampOnStack[2] = (uint32_t)realFunc;
  36. trampOnStack[3] = (uint32_t)localsPtr;
  37. trampOnStack[4] = 0x7d6802a6; /* Lbase: mflr r11 */
  38. trampOnStack[5] = 0x818b0000; /* lwz r12,0(r11) */
  39. trampOnStack[6] = 0x7c0803a6; /* mtlr r0 */
  40. trampOnStack[7] = 0x7d8903a6; /* mtctr r12 */
  41. trampOnStack[8] = 0x816b0004; /* lwz r11,4(r11) */
  42. trampOnStack[9] = 0x4e800420; /* bctr */
  43.  
  44. /* clear instruction cache */
  45. __clear_cache(trampOnStack, &trampOnStack[10]);
  46. }

I don't know if this works as a replacement though.

hypex
hypex's picture
Offline
Last seen: 1 month 2 weeks ago
Joined: 2011-09-09 16:20
I must say this looks pretty

I must say this looks pretty bad. Why is mpeg2desc using self modified code on PPC of all things? Does it do the same for x86?

That's very nice when speeding things up but I don't see any core optimisations here, just an ASM hack to call a function. Why can't mpeg2desc do it in normal C functions calls? :-?

salass00
salass00's picture
Offline
Last seen: 1 year 1 month ago
Joined: 2011-02-03 11:27
Re: Undefined reference to '__trampoline_setup'

I'm resurrecting this thread because I've ran into this same problem again while updating the dvdauthor port to version 0.7.2.

Doing some googling I found mention of an ld option "--no-trampoline" so I tried adding "-Wl,--no-trampoline" to LDFLAGS. It didn't work, ld says the --no-trampoline option is unrecognised.

salass00
salass00's picture
Offline
Last seen: 1 year 1 month ago
Joined: 2011-02-03 11:27
Re: Undefined reference to '__trampoline_setup'

@hypex

The mpeg2desc code is normal C code. The __trampoline_setup call is generated by the gcc compiler.

Also it's not self modifying code since the code is not modifying itself.

salass00
salass00's picture
Offline
Last seen: 1 year 1 month ago
Joined: 2011-02-03 11:27
Re: Undefined reference to '__trampoline_setup'

Found this:

https://gcc.gnu.org/onlinedocs/gccint/Trampolines.html

No mention of how to disable this feature though, or why it might not be working correctly with our gcc port.

salass00
salass00's picture
Offline
Last seen: 1 year 1 month ago
Joined: 2011-02-03 11:27
Re: Undefined reference to '__trampoline_setup'

Finally got mpeg2desc to compile by undefining HAVE_NESTED_ROUTINES in "config.h".

Apparently gcc has a non-standard extension called nested functions which means that you can have a function defined inside a function that will also have full access to all the local variables in the parent/surrounding function (useful for callback functions) and mpeg2desc was making use of this functionality.

https://gcc.gnu.org/onlinedocs/gcc/Nested-Functions.html

xenic
xenic's picture
Offline
Last seen: 1 year 11 months ago
Joined: 2011-05-07 04:52
Re: Undefined reference to '__trampoline_setup'

@salass00
Nested Procedures (functions) are common in Modula-2 and probably Oberon. However, it looks to me like setting up trampolines wouldn't be very effecient when in C you could just declare all the parent variables in a structure and pass the structure pointer to the sub-function. Maybe I'm just misunderstanding what trampolines are doing.

X1000 - OS 4.1FE

hypex
hypex's picture
Offline
Last seen: 1 month 2 weeks ago
Joined: 2011-09-09 16:20
Re: Undefined reference to '__trampoline_setup'

@ salass00

The mpeg2desc code is normal C code. The __trampoline_setup call is generated by the gcc compiler.

No doubt caused by those nested functions. Which I like the idea of since you can freely do it in ASM. But I still wonder why our GCC lacks the trampoline.

Also it's not self modifying code since the code is not modifying itself.

Okay technically not. But it still builds up a cache of instructions by hand so still a hack! :-D

Like on 68K the instruction cache would need flushing out. As part of ASM generated code in the assembler that would be fine. But it still looks dirty without using actual portable C code to do the operation.

Log in or register to post comments