Re: [edk2] objcopy option "--add-gnu-debuglink"

Subject: Re: [edk2] objcopy option "--add-gnu-debuglink"

From: nicolas <nicolas1968@163.com>

To: edk2-devel@lists.sourceforge.net

Date: 2012-11-30 02:42:05

 hi, Andrew:

Thank you very much!

Your explanation is very clear!

 

So, why not del "-g" flag from RELEASE_ARMGCC_ARM_CC_FLAGS IN tools_def.txt ?

So, the release version binary could be smaller!

 

best wishes,

 

 


: Andrew Fish [mailto:afish@apple.com]
:
20121129 18:25
:
edk2-devel@lists.sourceforge.net
: Re: [edk2] objcopy option "--add-gnu-debuglink"

 

 

On Nov 29, 2012, at 1:59 AM, nicolas wrote:



 hi, Andrew:

Thanks for your response!

So, take ArmPkg\Drivers\CpuDxe as an example:

In Build\...\CpuDxe\CpuDxe\DEBUG directory, there are 3 files:

ArmCpuDxe.dll

 

This is usually the file that was processed to produce ArmCpuDxe.efi PE/COFF image and it contains the symbols. (not true for VC++ as the symbols end up in a .pdb file)



ArmCpuDxe.efi

 

EFI PE/COFF image



ArmCpuDxe.map 

Human readable map file to show you where stuff got linked

 

So, which file is the debug symbol file ?

It seems uefi code would get the symbol file from ArmCpuDxe.dll .

 

If i want to use gdb to debug ArmCpuDxe.efi, what is the steps?

 

add-symbol-file ArmCpuDxe.efi   0xABC00240

 

Where 0xABC00240 is the load address + sizeof the PE/COFF header. 

 

It is possible to write gdb scripts to load EFI symbols, I'm not sure if one exists in the edk2?



 

best wishes,

 


: Andrew Fish [mailto:afish@apple.com]
:
20121129 17:39
:
edk2-devel@lists.sourceforge.net
: Re: [edk2] objcopy option "--add-gnu-debuglink"

 

 

On Nov 29, 2012, at 1:14 AM, nicolas wrote:




 hi, Andrew:

Thanks for your response!

I found gcc has "-g " parameter in tools_def.txt.

So, it means :

the produced efi image file has included debug info sections?

 

-g means produce debug information for the symbols file. 




And the efi code could retrieve the symbol file from the loaded EFI image?

 

 

From a PE/COFF point of view the debug information is just the file name of the symbol file. So for example this looks like this flag is used to point the EFI  PE/COFF image at the symbol file. 

 

DEBUG_*_*_OBJCOPY_ADDDEBUGFLAG     = --add-gnu-debuglink=$(DEBUG_DIR)\$(MODULE_NAME).debug
RELEASE_*_*_OBJCOPY_ADDDEBUGFLAG   =

 

 




best wishes,

 


: Andrew Fish [mailto:afish@apple.com]
: 20121127
4:05
:
edk2-devel@lists.sourceforge.net
: Re: [edk2] objcopy option "--add-gnu-debuglink"

 

Nicolas,

 

I don't know the specific answer for your tools, but I can give you a hint on how things work in general. 

 

The general answer is no one actually uses the debug definitions defined in COFF or PE/COFF. The PE/COFF file points to another file that contains the debug information. For Visual Studio this is a .PDB  file, for clang we point to a DWARF or DSYM (DWARF + objects).

 

If you look in the PE/COFF specification (http://msdn.microsoft.com/en-us/library/windows/hardware/gg463119.aspx) there is something called the Optional Header Data Directories, the term optional here is confusing as it is optional for COFF, but required for PE/COFF. For most EFI images you will see a Base Relocation Entry, and Debug Data Directories entries (assuming it is  debug build). The Base Relocation Entry contains the fix up info so an image can be loaded at other than its linked address (usually zero). The Debug Data Directory entry looks like EFI_IMAGE_DEBUG_DIRECTORY_ENTRY

and it points to a EFI_IMAGE_DEBUG_CODEVIEW_RSDS_ENTRY or one of the other types you can find in https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2/MdePkg/Include/IndustryStandard/PeImage.h.

 

Basically a EFI_IMAGE_DEBUG_CODEVIEW_RSDS_ENTRY contains the file name of the symbols. So loading symbols in EFI usually involves walking the PE/COFF image to find the PDB (or other debug file path and name), and this combined with the load address of the PE/COFF image is enough to load symbols in a debugger. There are library functions that do all this, and you can find them by searching for one of the PE/COFF structures I mention in this mail. 

 

On a related side note PE/COFF differs from ELF and Mach-O in that the file header is loaded into system memory. Why do I mention this? Well if the build system is converting EFL/Mach-O files to PE/COFF you generally have to link the ELF/Mach-O file not at zero, but use the size of the PE/COFF header as the link address. The reason I mention this is that sometimes when you load symbols you need to add back in the size of the PE/COFF header to the PE/COFF image load address to get the correct symbol addresses. This shift is only required for PE/COFF images that are converted from ELF or Mach-O. 

 

Thanks,

 

Andrew Fish

 

 

On Nov 22, 2012, at 9:40 PM, nicolas wrote:





hi, experts:

I found a line in tools_def.txt :

DEBUG_*_*_OBJCOPY_ADDDEBUGFLAG     = --add-gnu-debuglink=$(DEBUG_DIR)\$(MODULE_NAME).debug

 

Will it merge debug info file into efi binary?

Or it will produce a separate debug info file?

 

best wishes,



------------------------------------------------------------------------------
Monitor your physical, virtual and cloud infrastructure from a single
web console. Get in-depth insight into apps, servers, databases, vmware,
SAP, cloud infrastructure, etc. Download 30-day Free Trial.
Pricing starts from $795 for 25 servers or applications!
http://p.sf.net/sfu/zoho_dev2dev_nov_______________________________________________
edk2-devel mailing list
edk2-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/edk2-devel

 



------------------------------------------------------------------------------
Keep yourself connected to Go Parallel:
VERIFY Test and improve your parallel project with help from experts
and peers.
http://goparallel.sourceforge.net_______________________________________________
edk2-devel mailing list
edk2-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/edk2-devel

 



------------------------------------------------------------------------------
Keep yourself connected to Go Parallel:
VERIFY Test and improve your parallel project with help from experts
and peers.
http://goparallel.sourceforge.net_______________________________________________
edk2-devel mailing list
edk2-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/edk2-devel