Linker "wrap" feature

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am attempting to "wrap" calls to malloc (see thread http://www.avrfreaks.net/forum/instrumenting-malloc-free#comment-2393596)

 

When I add the --wrap=malloc option to the link step in the Atmel Studio build I get the error:

 

avr-g++.exe(0,0): error: unrecognized command line option '--wrap=malloc'

 

The link step is:

 

Invoking: AVR8/GNU Linker : 4.9.2
        "C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-g++.exe" -o BC002.elf  ADC.o BlockCtrl_3.o ButtonBlock.o Can.o CMem.o Config.o ControllerMonitor.o Diagnostics.o Expression.o ExpressionRunTime.o IO_cl.o IO_PCA9554_cl.o IO_TLC59116_cl.o ISignal.o Ladder.o LinkedList.o main.o MCP2515.o Memory.o MultiSelect.o NetMsgs.o Relay.o Restart.o SignalHead.o spi.o Spy.o Switch.o TrackIn.o TWI.o Utils.o Utils_CPP.o Work.o XBee.o   -Wl,-Map="BC002.map" -Wl,--start-group -Wl,-lm  -Wl,--end-group -Wl,--gc-sections -mmcu=atmega1284p -B "C:\Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.0.90\gcc\dev\atmega1284p" --wrap=malloc

 

Is this feature not available in the AVR GCC toolchain?

 

Regards,

 

Chuck

This topic has a solution.
Last Edited: Wed. Feb 14, 2018 - 04:21 AM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

From a command prompt type "C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-g++.exe" --help

 

From there you will see the avr-g++.exe command is a stub program that calls the various steps (preprocessor, assembler, linker, etc.).  One option to avr-g++.exe that looks promising is the -Wl option, to pass arguments to the linker.  So try -Wl,--wrap=malloc

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
-Wl,--wrap=malloc

 

Stefan Ernst

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

And more generally -Wl, prefix on commands to be directed to the linker (also -Wa, for any to the assembler and -Wp, for any to the preprocessor). The "compiler driver" will pass options it knows to be unique to the right target but if there's any doubt then help it along and tell it where the commands are to be directed.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Using "-Wl,--wrap=malloc" in the Atmel Studio "Other Linker Flags" box worked.

 

Silly me, I assumed (always bad ..) that entering "--wrap=malloc" into the "Other Linker Flags" box would be passed to the linker (i.e.: "-Wl," added) ... my bad.

 

Thanks to all for the assist.

 

Chuck Hackett