This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

What is -fdata-sections in gcc?

Hello, my old question: https://devzone.nordicsemi.com/f/nordic-q-a/48087/nrf51822-s130-hardfault-error

I found something.

After removing -fdata-sections in makefile, Hardfault error in my old question never occur. 

What is role of data-sections flag?

I want to know purpose and role of this flag.

From https://gcc.gnu.org/onlinedocs/gcc-2.95.2/gcc_2.html#SEC10

-ffunction-sections-fdata-sectionsPlace each function or data item into its own section in the output file if the target supports arbitrary sections. The name of the function or the name of the data item determines the section's name in the output file.

Use these options on systems where the linker can perform optimizations to improve locality of reference in the instruction space. HPPA processors running HP-UX and Sparc processors running Solaris 2 have linkers with such optimizations. Other systems using the ELF object format as well as AIX may have these optimizations in the future.

Only use these options when there are significant benefits from doing so. When you specify these options, the assembler and linker will create larger object and executable files and will also be slower. You will not be able to use gprof on all systems if you specify this option and you may have problems with debugging if you specify both this option and `-g'.

Parents Reply
  • This is what happens when I try to access the wrong handler address.

    my actual handler address is 0x200010 (example). 

    and compare value of variable containing handler address in another module.

    it is contaminated partially.

    (gdb) print actual_handler

    0x200010

    (gdb) print m_evt_handler ( in another module)

    0x2000ff

    so I try to debugging upper m_evt_handler address. 

    (gdb) x/256b (m_evt_handler address-0x80)

    0x20004a58 <m_read_buf>:        0xff    0xff    0xff    0xff    0xff   0xff    0xff   0xff

    .... 

    0x20004aXX <m_read_buf>:        0xff    0xff    0xff    0xff    0xff   0xff    0xff   0xff

    0x20004aXX <m_read_buf>:        0xff    0xff    0xff    0xff    0xff   0xff    0xff   0xff

    0x20004aXX <m_read_buf>:        0xff    0xff    0xff    0xff    0xff   0xff    0xff   0xff

    0x20004aXX <m_evt_handler>:        0xff    0x00    0x20    ....

    and I check the usage of m_read_buf in my code. and I found overrun bug.

Children
No Data
Related