This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

.const section does not load into memory



Hi All,

I am building an image for an M3 core and having trouble with the .const section not being loaded into memory.  Other sections load correctly.


Output from readelf -l

Program Headers:
  Type            Offset         VirtAddr          PhysAddr       FileSiz    MemSiz  Flg Align
  LOAD           0x000034 0x00000000 0x00000000 0x0003c 0x0003c R E 0x4
  LOAD           0x000070 0x000007f0 0x000007f0 0x00000 0x00010 RW  0x4
  LOAD           0x000070 0x00000800 0x00000800 0x00140 0x00140 R   0x4
  LOAD           0x0001b0 0x00100000 0x00100000 0x2524be 0x2524be R E 0x4
  LOAD           0x252670 0x003524c0 0x003524c0 0x00000 0x11bac9 RW  0x10   <---- This is the .const section.  It does not load.
  LOAD           0x252670 0x0046df8a 0x0046df8a 0x00072 0x00072 R E 0x2

Notice that the .const section shows up with 0x0 FileSize in the binary.  I am linking in several components which is why the section is large.  What could be causing the linker to not include constants?  I am using 4.9.0 version of the tool chain and building with ELF for omap4.\

Thanks.

  • What does ofd470 say for the same program?  ofd470 is an object file dump utility, as readelf is, but ofd470 is customized for TI devices.

  • I believe this is the relevant output.  Is there anything I should look for?

     

    Program Segment Table
     
        ...
        <5>
           Segment Type:  PT_LOAD     File Offset:   0x002526f0
           Run Address:   0x00352540  Load Address:  0x00352540
           File Size:     0x0         Memory Size:   0x1a0ebc
           Flags:         rw-         Alignment:     16
                                      Contains:      Section 26 (tools_log_buffer)
                                      Contains:      Section 27 (.awb_scratch)
                                      Contains:      Section 30 (.const)
        ...

     Section Information

        <26> "tools_log_buffer"
           Load Address:        0x004dd80c  Run Address:        0x004dd80c
           Size:                0x10000     Alignment:          4        
           Loaded Onto Device:  Yes         Address Unit Size:  8 bits   
           File Offset:         0x003dd9bc  # Relocs:           0        
           Section Type:        SHT_NOBITS  ELF sh_flags:       0x00000003
           ELF sh_flag:         SHF_WRITE   ELF sh_flag:        SHF_ALLOC
           TI ext_flags:        0x0                                      

        <27> ".awb_scratch"
           Load Address:        0x004ed80c  Run Address:        0x004ed80c
           Size:                0x5bf0      Alignment:          1        
           Loaded Onto Device:  Yes         Address Unit Size:  8 bits   
           File Offset:         0x003ed9bc  # Relocs:           0        
           Section Type:        SHT_NOBITS  ELF sh_flags:       0x00000003
           ELF sh_flag:         SHF_WRITE   ELF sh_flag:        SHF_ALLOC
           TI ext_flags:        0x0                                      

       ...                                      

        <30> ".const"
           Load Address:        0x00352540  Run Address:        0x00352540
           Size:                0x18b2c9    Alignment:          16       
           Loaded Onto Device:  Yes         Address Unit Size:  8 bits   
           File Offset:         0x002526f0  # Relocs:           0        
           Section Type:        SHT_NOBITS  ELF sh_flags:       0x00000003
           ELF sh_flag:         SHF_WRITE   ELF sh_flag:        SHF_ALLOC
           TI ext_flags:        0x0                                      
        ...

  • The ofd470 output agrees with readelf.

    I don't know what to make of this, and this is a bit beyond my expertise for me to be able to guess the cause without a test case.  Unless someone else has a flash of insight, we'll need to see a test case.

  • The .const section is uninitialized.  That is not expected.  So, we should focus on explaining that.

    Please show ofd470 output for the .const section of some object file that is input to the link.  That should show that .const is an initialized section.  

    Also show the line(s) in the link command file which create the .const output section.  There might be something interesting there.

    Thanks and regards,

    -George

  • Near const data objects will be accessed via DP-relative addressing, so they may be uninitialized.

    You can force const data objects to be directly initialized by using the --mem_model:const=far compiler option.

    Regards,

    Todd Snider

  • Erm, sorry. That DP-relative comment applies to C6x. You are using M3.

    To get at the root of why the .const section is uninitialized, you'll want to look at all the section header information of all the input .const sections that went into the .const output section. If one of those is marked with SHF_WRITE, then we need to find out why.

    To get the section header information about an input section, run "ofd470 -v input.obj" on the file that contains the input section. Look for the input section in the OFD output.

    - Todd

  • Todd,

    Some of the ofd470 output is shown in an earlier email above.  The .const section does show a SHF_WRITE flag.

       <30> ".const"
           Load Address:        0x00352540  Run Address:        0x00352540
           Size:                0x18b2c9    Alignment:          16
           Loaded Onto Device:  Yes         Address Unit Size:  8 bits
           File Offset:         0x002526f0  # Relocs:           0
           Section Type:        SHT_NOBITS  ELF sh_flags:       0x00000003
           ELF sh_flag:         SHF_WRITE   ELF sh_flag:        SHF_ALLOC
           TI ext_flags:        0x0

  • Is this the OFD output from the linked application or one of the input object files?

    What I suspect is that most of the .const sections that are coming from the input object files and libraries are read-only, but at least one of them will have the SHF_WRITE flag on for some reason.

    You'll want to look at the map file to see what .const input sections go into the .const output section. The map file will also tell you which input file each input section comes from. Then you can run ofd470 on each of those input files to find the .const input section that is marked with SHF_WRITE.

    - Todd