title: GNU LD: How to override a symbol value (an address) defined by the linker script specified using -T
body: <p>My usecase is as follows: </p>
  
  <ul>
  <li>I am using a typical SDK that comes with Makefile based projects</li>
  <li>I belive the linker is patched gcc. gcc --version gives me 4.3.4</li>
  <li>SDK defines the linker script (lets call it Linker.ld)</li>
  <li>Linker.ld includes LinkerMemMap.cfg, which defines the absolute addresses for various sections in the linked ELF image</li>
  <li>SDK provides application templates based on Makefiles (GNU Make 3.81) and make itself</li>
  <li>In the SDK provided Makefile template, when <b>gcc</b> is invoked the Linker.ld is provided with -T command line option, as follows:</li>
  </ul>
  
  <p><code>gcc $(OBJS) -l$(Lib1) -l$(Lib2) -nostdlib -lgcc -L$(library_path) -g -msmall-mode -mconst-switch-tables -mas-mode -mno-initc -Wl,--start-group,--end-group,-T,$(PATH_TO_Linker.ld),--gc-sections -o$(OUTPUT).elf</code></p>
  
  <p>My requirement is as follows:</p>
  
  <ul>
  <li>I would like to use the sections as defined in Linker.ld and use the memory map as per LinkerMemMap.cfg however tweak a particular symbol(lets call it SYMBOL_RAM_START) defined in LinkerMemMap.cfg</li>
  </ul>
  
  <p>What works:</p>
  
  <ul>
  <li>I have tried in the makefile, prior to linking the final ELF image, copy the LinkerMemMap.cfg (which is included by Linker.ld) to the build directory and patch it to redefine SYMBOL_RAM_START. This <b>does work</b> as the linker searches for the linker scripts and the files included by the linker scripts in the current folder first.</li>
  </ul>
  
  <p>What doesn't:</p>
  
  <ul>
  <li><p>Unfortunately our stakeholders think the above method is too risky and complex to understand. I would like to override the symbol value on the linker command line with something like below:</p>
  
  <ol>
  <li><p><code>gcc $(OBJS) -l$(Lib1) -l$(Lib2) -nostdlib -lgcc -L$(library_path) -g -msmall-mode -mconst-switch-tables -mas-mode -mno-initc -Wl,--start-group,--end-group,-T,$(PATH_TO_Linker.ld),--gc-sections,<b>--defsym=SYMBOL_RAM_START=$(VALUE_TO_OVERRIDE)</b> -o$(OUTPUT).elf</code></p></li>
  <li><p><code>gcc $(OBJS) -l$(Lib1) -l$(Lib2) -nostdlib -lgcc -L$(library_path) -g -msmall-mode -mconst-switch-tables -mas-mode -mno-initc -Wl,--start-group,--end-group,-T,$(PATH_TO_Linker.ld),--gc-sections <b>--defsym=SYMBOL_RAM_START=$(VALUE_TO_OVERRIDE)</b> -o$(OUTPUT).elf</code></p></li>
  <li><p><code>gcc $(OBJS) -l$(Lib1) -l$(Lib2) <b>--defsym=SYMBOL_RAM_START=$(VALUE_TO_OVERRIDE)</b> -nostdlib -lgcc -L$(library_path) -g -msmall-mode -mconst-switch-tables -mas-mode -mno-initc -Wl,--start-group,--end-group,-T,$(PATH_TO_Linker.ld),--gc-sections -o$(OUTPUT).elf</code></p></li>
  </ol></li>
  </ul>
  
  <p>None of these seem to have any effect on the linked image created by the linker.</p>
  
  <ul>
  <li>Can --defsym override the symbols defined by linkerscript specified using -T?</li>
  <li>Could any of you please see what am I doing wrong here? </li>
  </ul>