1. This forum section is a read-only archive which contains old newsgroup posts. If you wish to post a query, please do so in one of our main forum sections (here). This way you will get a faster, better response from the members on Motherboard Point.

How a function could crash the program which is not called

Discussion in 'Embedded' started by riggs, Aug 30, 2012.

  1. riggs

    riggs Guest

    Hello, I just define a function but i have not called it yet...but i
    crashed...
    There is no memory limit problem i have checked and there is not much loca
    variables which might cause stack overflow.... any idea
     
    riggs, Aug 30, 2012
    #1
    1. Advertisements

  2. riggs

    Rich Webb Guest

    You used a = i++ on line 583 which caused the compiler to generate
    bad code.
     
    Rich Webb, Aug 30, 2012
    #2
    1. Advertisements



  3. In the very, very unlikely case that the problem is not what Rich's
    suggests, it is possible that adding this function, (written in an
    unknown language, for an unknown platform, using unknown tools, with
    the wind blowing from an unknown direction,) changed the memory layout
    of your program so an existing memory corruption problem, which was
    harmless or at least undetected before, is now visible.

    Please read
    http://www.catb.org/~esr/faqs/smart-questions.html
    http://www.petri.co.il/how_to_ask_a_question.htm
     
    Roberto Waltman, Aug 30, 2012
    #3
  4. riggs

    Tim Wescott Guest



    That's what I would have said. Probably even after knowing the pertinent
    details. It's not the world's commonest problem -- but that signature is
    pretty telling.

    --
    My liberal friends think I'm a conservative kook.
    My conservative friends think I'm a liberal kook.
    Why am I not happy that they have found common ground?

    Tim Wescott, Communications, Control, Circuits & Software
    http://www.wescottdesign.com
     
    Tim Wescott, Aug 30, 2012
    #4
  5. riggs

    riggs Guest


    My compiler is GCC and platform is ARM9 processor. I read linker scrip
    file and i found that layout is made according to code text size. But if
    dont call a function why linker add assembly function to executable file.
    tried to make the .text section of program larger, but no need to rea
    linker script because linker script make layout acording to code size. S
    there is no way to add code to project. Now my solution is to eleminat
    some less needless codes from my project, because i have very small size o
    memory. Thanks for reading...
     
    riggs, Aug 31, 2012
    #5
  6. [Since you are using gcc, I am assuming you are using binutils to do
    the linking.]

    The comments about layout according to code size don't make any sense at
    all. You can split code by function (say, for example, a bootloader which
    needs to live in it's own unique hardware specific region) but that is not
    size related. Have you misunderstood what is going on here ?

    The basic purpose of a linker script is for you to tell the linker what
    address regions it can write to, the size of those regions and which
    bits of your program you want in the various regions. The linker then
    takes your program and places it in those regions.

    The only size directives should be the ones which describe the physical
    layout of your board's memory and these have no relationship to the
    actual size of your code. Could the real problem be that your code is
    simply too large for the board you are trying to run it on ?

    If you have not done so already, have the linker generate a map listing
    and make sure that the various parts of your program are going where you
    expect and make sure that your program can physically fit in those
    regions.

    If you are doing anything unusual with size directives, you need to state
    _exactly_ what you are doing.

    Simon.
     
    Simon Clubley, Aug 31, 2012
    #6
  7. riggs

    Tim Wescott Guest



    What Simon said: this comment doesn't seem to make much sense, unless
    you're using an automatically-generated linker script, which is not at
    all correct for embedded work.
    Because you told it to -- you did write the function, after all.
    Traditionally the semantics for telling the linker "only add this code if
    I need it" is to put it in a library. Gnu has a method for doing this
    function-by-function in a code file but I can't remember all the details,
    and it's very "gnu-ish" (it uses an attribute, I _think_ that attribute
    is "weak", but I'm not at all sure -- RTFM).
    If your linker is making your script, then you're doing something wrong
    for embedded work. You need to make the script (well, if you're a normal
    human you need to find a script that's close, and modify it for your
    processor).

    --
    My liberal friends think I'm a conservative kook.
    My conservative friends think I'm a liberal kook.
    Why am I not happy that they have found common ground?

    Tim Wescott, Communications, Control, Circuits & Software
    http://www.wescottdesign.com
     
    Tim Wescott, Aug 31, 2012
    #7
  8. riggs

    Rob Gaddi Guest

    Two things. On ARM targets I generally find you want to use the
    -ffunction-sections and --gc-sections arguments. The first causes each
    function to be compiled into it's own section under .text, such
    as .text.my_func, etc. That improves the locality of your functions,
    which is useful in that it keeps your constant pools closer to the
    executable code, which allows for efficient addressing. But also,
    because it's in its own section, the second option (strip unused
    sections) will take it out of your executable.
     
    Rob Gaddi, Aug 31, 2012
    #8
  9. riggs

    Mel Wilson Guest

    "Weak" is the one that lets you put default catch-all interrupt handlers
    into one module (declared as weak), and have the handlers in the real code
    replace them in the vector.

    Mel.
     
    Mel Wilson, Aug 31, 2012
    #9
  10. riggs

    Tauno Voipio Guest

    'weak' means that the linker does not complain if the symbol is already
    defined elsewhere - it simply ignores the piece of code, if it comes
    from a library file. 'weak' is intended to provide defaults for symbols
    that may be present or absent.

    The linker is able to take or leave input file sections, so the process
    for unneeded code or data is two-step:

    1. Make the compiler to translate each function into a separate section
    with the --ffunction-sections switch. For module-wide data the
    corresponding switch is --fdata-sections.

    2. Make the linker to drop unused sections with the --gc-sections
    switch.

    It is not always a good idea to drop data sections, as it may
    complicate the addressing of module-wide data.
     
    Tauno Voipio, Aug 31, 2012
    #10
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.