19347

ELF loading when VMA != LMA

Question:

<hr />

I have a problem on this one. I am using ARM Cortex-A9 with DS-5 to create baremetal firmware. I modified my linker file to intentionally put the .data section LMA adjacent to the text and rodata sections, because its default run-time VMA is located 1MB away and the .bin image is around 1MB but containing 90% zeroes. And so I intentionally made LMA != VMA to save space. I also added a code in start.S that relocates the .data section from its lma to vma.

However on loading the resulting elf file in DS-5, it already loads all section to their VMA. As a result, my start.S code that is supposed to relocate data, copied from the LMA with garbage content to the already correct VMA, and soon afterwards those garbage resulted to fault.

I've had experience with unequal VMA and LMA in binary in Cortex-M4 and used gdb for its elf debugging, and there were no problems there, but it was microcontroller. In my current arm processor application, how would I then simulate in elf debugging the scenario of correctly copying data from its LMA to VMA. Most likely when booting standalone using the binary format there will be no problems, but right now we're still in elf debugging so I have to fix this.

Answer1:

Problem solved... I'd like to share the solution given to me:

It helps to realize that "VMA" and "LMA" are GNU utility terminology and not in the ELF specification. Once you get down to looking at it from interpreting an ELF executable file, you will find that there is a program header field called "p_paddr" and another called "p_vaddr" - that makes it easier to search for! The option you need in DS-5 to use p_paddr is:

ARM DS-5 Debugger Command Reference : 1.3.138 set elf load-segments-at-p_paddr

By default, DS-5 uses p_vaddr, which is the standard. Usage of p_paddr is a quality of implementation, and is left very loosely defined in the specification. The ARM Compiler, Linker and C Library doesn't generate this information since the relocation process is handled internally (scatter loading). Some environments use p_paddr not as a physical address, but the load address (hence "LMA"), and some use it as an address to resolve symbols before and after MMU is enabled..

Recommend

  • new svn server, same ip
  • Building libunwind for Mac
  • NodeJs Google Compute Engine Invalid ELF Header when using 'gcloud' module
  • Change entry point with gnu linker
  • addr2line not woking on Ubuntu 16.10?
  • SVN and renaming the server it's running on
  • XCTest for existing project
  • C++ String tokenisation from 3D .obj files
  • Scala split a multi line string by lines that contain all hyphens
  • Get all existing pointers to an object
  • Java Garbage collection, setting reference to null
  • Insert records if not exist SQL Server 2005
  • Why is django manage.py syncdb failing to create new columns on my development server?
  • You tube videos are not playing
  • ImportError: cannot import name Pubnub
  • why calling cd shell command through system() or execvp() from a child process won't work?
  • Where these are stored?
  • Problem with Django using Apache2 (mod_wsgi), Occassionally is “unable to import from module” for no
  • How to display special characters in SQL server 2008?
  • extjs4 catching the scroll event on panel
  • there is no graph with tensorboard
  • Repository Browser Only - \"Repository moved permanently to… please relocate”
  • Cannot upload to OneDrive using the new SDK
  • Loading .coffee files via a view in Rails
  • Word Open XML Mail Merge
  • Controls, properties, events and timers running in design time
  • Running a C# exe file
  • php design question - will a Helper help here?
  • using conditional logic : check if record exists; if it does, update it, if not, create it
  • AngularJs get employee from factory
  • python regex in pyparsing
  • Acquiring multiple attributes from .xml file in c#
  • Free memory of cv::Mat loaded using FileStorage API
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • Android Google Maps API OnLocationChanged only called once
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • Authorize attributes not working in MVC 4
  • How can I remove ASP.NET Designer.cs files?
  • java string with new operator and a literal
  • How can I use threading to 'tick' a timer to be accessed by other threads?