#2281 Linker doesn' know where the interrupt vectors must be placed


Symptoms: when building for Cypress FX2 chip (8051 compatible), firmware working or not working randomly, depending on linking order. Disassembling with IDA reveals that some functions from CSEG may be placed at address 0x0000, if they are short enough to feat before address 0x43, which is used for USB interrupts. The bug is that interrupt vectors are defined in "HOME" area, which MUST be placed at address 0x0000 with highest priority. Please, fix that. In current versions of SDCC (I tried 3.4.0-win32 and 3.3.0-win32) the linker can place CSEG before HOME. I've found a temporary solution by relocating CSEG with command -Wl-bCSEG=0x0080, wasting half of a day for that... And this fix works only until some other code section appears in source files.
Any additional information by request.


  • Philipp Klaus Krause

    Are you using a custom crt0? If yes, does it contain the correct information for the ordering of the segments?


    Last edit: Philipp Klaus Krause 2014-06-29
  • Sergey

    Sergey - 2014-06-30

    No, I've just installed SDCC from .exe installer. Building code via Code::Blocks. SDCC manual doesn't contain instructions of how to set section's priorities. Settings HOME address to 0x0000 doesn't work, because CSEG has the same address by default (if not moved) and gets higher priority. Setting CSEG address to 0x0001 doesn't work either, linker places HOME after CSEG again. We need some mechanism to set section's priorities directly, no by base address.

  • Maarten Brock

    Maarten Brock - 2014-06-30

    Every file generated by SDCC and every asm file in the library has the HOME and CSEG areas defined in the right order for the linker. The result is that the linker "hears about" HOME first before CSEG and thus will place it first. If you add your own asm file with only CSEG defined and link it first then this might happen. Add an empty HOME area before your CSEG and it should work ok.

    • Sergey

      Sergey - 2014-06-30

      Thanks, Maarten, your explanation solved the problem. My code is based on Cypress examples, which have some asm files. Adding empty HOME sections into them solved the problem. That linker feature must be mentioned in manual, because I've never seen HOME sections in custom .asm files for that Cypress chip. So, all that sample projects are suspectable to described problem.

  • Sergey

    Sergey - 2014-06-30

    Another problem was found. According to linker documentation "The relocation and/or concatenation of an area containing .bndry directives to place code at specific boundaries will NOT maintain the specified boundaries." That's why USB descriptors not working sometimes. You can argue, that is a specific "feature" of linker (in addition to messed up segments), but it is really makes sdcc very useless for newbies.

  • Ben Shi

    Ben Shi - 2015-07-22

    Maybe some clear explanation about is needed in the manual.

  • Ben Shi

    Ben Shi - 2015-07-22
    • Category: other --> sdld

Log in to post a comment.