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.

C674x MATHLIB_RTS 3.1.0.0: Problem overriding RTS functions when compiling under EABI

Other Parts Discussed in Thread: MATHLIB, TMS320C6742

Hello,

I am having trouble overriding RTS functions when compiling under EABI using C674x MATHLIB_RTS version 3.1.0.0. At first I was trying to build the MATHLIB_RTS library myself, but eventually I used the pre-built library that comes in the installation with the same result (C:\ti\mathlib_rts_c674x_3_1_0_0\packages\ti\mathlib\lib\mathlib_rts.lib). Here are the steps to reproduce the problem:

1. Create a new CCS project (I'm using v6 with all the latest updates).

Target: C674x Floating-point DSP - TMS320C6742
Compiler version: TI v7.4.11
Output format: eabi (ELF)
Template: Empty Project (with main.c)

2. Use the following main.c:

#include <math.h>

int main(void)
{
    double a = 1, b = 1, c, d;
    c = atan2(a, b);
    d = a / b;
    return 0;
}

3. Build the project. The assembly output shows the following calls:
    CALLP .S2 atan2,B3
    CALLP .S2 __c6xabi_divd,B3
    We have not linked the MATHLIB yet, so looking at the MAP file shows that ".text:atan2" and ".text:__c6xabi_divd" are coming from rts6740_elf.lib.

4. Now add MATHLIB_RTS to the TOP of the linker's "File Search Path" list of included library files. The list will then look like this:
    "C:\ti\mathlib_rts_c674x_3_1_0_0\packages\ti\mathlib\lib\mathlib_rts.lib"
    "libc.a"

5. Rebuild the project. The assembly output shows the same two calls as before.

  • Looking at the map file shows that ".text:atan2" no longer exists, and the locations of the symbols "atan2" and "atan2dp" are the same. This means that "atan2" is properly being overridden by MATHLIB_RTS.
  • However, the map file shows that ".text:__c6xabi_divd" still exists and is coming from rts6740_elf.lib. Furthermore, the locations of "__c6xabi_divd" and "divdp" are not the same. This means that "__c6xabi_divd" is not being overridden by MATHLIB_RTS.

Thank you in advance for your assistance!

Best regards,
Dave

  • Dave,

    This question appears to be specific to MATHLIB and not TI-RTOS, so I went ahead and moved this thread over to the device forum in hopes that it will get a faster response there.
  • David, thank you. I would like to note that the reason I created the post in TI-RTOS is that the current MATHLIB_RTS release notes state the following under the "Technical Support" heading:

    "Questions regarding the MATHLIB_RTS library should be directed to the Texas Instruments TI-RTOS E2E Forum. Please include the text "MATHLIB_RTS" in the title and add "C674x" and "MATHLIB_RTS" tags to your post."

    That being said, I certainly trust your judgement on where the thread should be to get the fastest response.

  • Hi Butters,

    Thanks for your post.

    If you have tested with the RTS override library version which would use RTS names such as atan2 and atan2f (override version) instead of atan2sp and atan2dp (normal version) and TI do not make a single RTS library that would include both normal names (atan2sp, atan2dp, divsp, divdp) and override names (atan2, atan2f, divf, div)

    In case, if you are building MATHLIB and you have to include atan2, div, atan2f, divf symbols which are RTS library names. There is a build option to compile with RTS names in which there is a RTS override option to generate RTS names and i think, you got trouble in just overriding RTS names but i presume that the RTS names for the desired symbols are included in the MATHLIB library. Do i mean correct?

    In case of RTS library symbol names, it could match in either sp or dp version in the current MATHLIB release since TI can provide one symbol in a library, so, may be, you could rebuild either sp RTS override or dp RTS override for C67x and for supported targets, TI can provide 3 libraries, the normal one, sp RTS override and dp RTS override.

    To add more insight to this RTS override & RTS library name build options for MATHLIB, please go through the below E2E post replied by TommyG and Yimin Zhang from page2:

    http://e2e.ti.com/support/embedded/tirtos/f/355/t/182789#pi239031349=2

    I guess, there shouldn't be any issues with these RTS normal library symbols (atan2dp, atan2sp, divsp, divdp). May be, you could see the MATHLIB 3.1.0.0 C674x test results for these symbols as below for your reference.

    http://software-dl.ti.com/sdoemb/sdoemb_public_sw/mathlib/latest//exports/MATHLIB_c674x_TestReport.html

    Thanks & regards,

    Sivaraj K

    -------------------------------------------------------------------------------------------------------

    Please click the Verify Answer button on this post if it answers your question.

    -------------------------------------------------------------------------------------------------------

  • Hello Sivaraj,

    Thank you for your response. I am familiar with the E2E post that you linked, as I have been referencing it quite a bit over the past few days. Please remember, however, that much of that post is discussing the organization of MATHLIB prior to version 3.1.0.0, so some of the specifics are not directly applicable to the current MATHLIB release.

    I think that you might have misunderstood the problem that I am having, or I failed to explain it concisely enough. Let me see if I can clarify things a bit. If possible, please try to reproduce my test case by doing the following simplified steps (between the horizontal lines):


    1. Create a new CCS project (I'm using v6 with all the latest updates).

      Target: C674x Floating-point DSP - TMS320C6742
      Compiler version: TI v7.4.11
      Output format: eabi (ELF)
      Template: Empty Project (with main.c)

    2. Use the following main.c:

      #include <math.h>
      int main(void)

      {
          double a = 1, b = 1;
          return (a / b);
      }

    3. Add MATHLIB_RTS to the TOP of the linker's "File Search Path" list of included library files. The list will then look like this:
      Library Description
      C:\ti\mathlib_rts_c674x_3_1_0_0\packages\ti\mathlib\lib\mathlib_rts.lib This is the MATHLIB_RTS library distributed by TI.
      libc.a This is the standard run-time support (RTS) library. Its arithmetic functions should be overridden by those in the MATHLIB_RTS library above.
    4. Build the CCS project and look at the MAP file that is generated by the linker. You will see that the linker has only used object code from rts6740_elf.lib, which is the standard run-time support library. Instead, the linker should have included object code from the MATHLIB_RTS library. This is the problem that I need to solve.

    Please let me know if this has clarified things. Finally, please note that this problem does not occur if the CCS project's output format is legacy COFF instead of EABI. In that case, the MAP file correctly shows that object code is being used from mathlib_rts.a674, which is the COFF build of MATHLIB_RTS.

    Thanks for your continued assistance.

    Best regards,
    Dave

  • Hi,

    Yes, i got clarified.

    Have you used little endianness / big endianness format? Actually, the device supports only little endianness for both ELF & COFF.

    Also, please ensure to validate the following tools as mentioned in the release notes:

    XDC Tools version: 8

    RTSC Packaging Standard version: 2.0

    C6000 Code Generation Tools version: 7.4.2

    Code Composer Studio version: V5

    GNU make version: 3.81

    After installing mathlib_rts_c674x_3_1_0_0, please check the MATHLIB_Users_Manual under docs folder as below:

    ~\ti\mathlib_rts_c674x_3_1_0_0\docs\MATHLIB_Users_Manual

    ~\ti\mathlib_rts_c674x_3_1_0_0\docs\doxygen\html\index.html

    May be, you could check the MATHLIB_RTS Build Process under "Compile MATHLIB_RTS for c674x (optional)"

    from the above mathlib user manual:

    ~\ti\mathlib_rts_c674x_3_1_0_0\docs\doxygen\html\buildprocess.html

    Thanks & regards,

    Sivaraj K

    -------------------------------------------------------------------------------------------------------

    Please click the Verify Answer button on this post if it answers your question.

    -------------------------------------------------------------------------------------------------------

  • Hello Sivaraj,

    I should not need to have the same versions of the tools mentioned in the release notes because I am not rebuilding the library myself. I am simply using the MATHLIB_RTS EABI binary that was pre-built by TI and installed with the MATHLIB_RTS executable:

    C:\ti\mathlib_rts_c674x_3_1_0_0\packages\ti\mathlib\lib\mathlib_rts.ae674

    I have read the User's Manual and the accompanying documentation, but I cannot find an answer as to why I cannot properly link the MATHLIB_RTS when using EABI instead of COFF. I really think there might be a bug in the EABI version because the COFF version works just fine out of the box.

    As far as the "Compile MATHLIB_RTS for c674x (optional)" build process, I really do not want to muddy the waters by rebuilding the library myself. As the user's manual says, "On installation, the MATHLIB_RTS libraries are built and ready to link. Therefore, this step is only required when the original kernel source code has been refined or contributions have been added."

    Would it be possible for someone at TI, preferably someone who is involved with maintaining MATHLIB_RTS, to look more closely at the mathlib_rts.ae674 library that is shipped with C674x MATHLIB_RTS 3.1.0.0 and try to determine why it is not linking with my simple example program?

    Thanks,
    Dave

  • Hi,

    For more technical clarification regarding mathlib_rts.ae674, it needs to be addressed by experts over TI-RTOS forum.

    I will redirect this post to TI-RTOS forum.

    Thanks & regards,
    Sivaraj K
  • Hi,

    Thank you for reporting the issue to us. RTS ELF library used __c6xabi_divd symbol for DP division, instead of __divd used by COFF library. Mathlib RTS override library only defined __divd and missed the symbol used in ELF library. This is on oversight on our part. Did you succeed in building the library? If yes, I can send you the source code change you need. If not, then we will fix this issue in the next release. The exact release schedule is still in the making. Sorry for the inconvenience. We appreciate your help in making Mathlib a better product.

    regards,

    Yimin

  • Hi Yimin,

    Thank you for looking into this and explaining the cause of the problem. Yes, I am able to build the library, so if you can send me the necessary source code changes it would be much appreciated. Thanks again for your help!

    Best regards,
    Dave

  • Hi Dave,

    Can you replace divdp.asm under mathlib_c674x_3_1_0_0\packages\ti\mathlib\src\divdp\c674 with the following content? I added a global symbol __c6xabi_divd. Can you let me know if it works for you? Thanks.

    regards,

    Yimin

    * ======================================================================== *
    * MATHLIB -- TI Floating-Point Math Function Library                       *
    *                                                                          *
    *                                                                          *
    * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/   *
    *                                                                          *
    *                                                                          *
    *  Redistribution and use in source and binary forms, with or without      *
    *  modification, are permitted provided that the following conditions      *
    *  are met:                                                                *
    *                                                                          *
    *    Redistributions of source code must retain the above copyright        *
    *    notice, this list of conditions and the following disclaimer.         *
    *                                                                          *
    *    Redistributions in binary form must reproduce the above copyright     *
    *    notice, this list of conditions and the following disclaimer in the   *
    *    documentation and/or other materials provided with the                *
    *    distribution.                                                         *
    *                                                                          *
    *    Neither the name of Texas Instruments Incorporated nor the names of   *
    *    its contributors may be used to endorse or promote products derived   *
    *    from this software without specific prior written permission.         *
    *                                                                          *
    *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS     *
    *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT       *
    *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR   *
    *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT    *
    *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,   *
    *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT        *
    *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,   *
    *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY   *
    *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT     *
    *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE   *
    *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.    *
    * ======================================================================== *

    * ======================================================================= *
    * divdp.asm - double precision floating point divide                      *
    *              optimized hand ASM single sample                           *
    * ======================================================================= *
            .if     __TI_EABI__
               .asg    divdp, _divdp
            .endif
            .global _divdp   ; entry labels
            .if (OVERRIDE_RTS = 1)
            .global __divd
            .global __c6xabi_divd
            .endif

            .sect ".text:optasm"


    __c6xabi_divd:
    __divd:                         ; entry in rts6701 library
    _divdp:                         ; ans = arg1 / arg2 (all DP FP)

            rcpdp   .S2     B5:B4, B7:B6            ; x1 = 1/arg2 [8-bits]     
    ||      zero    .L1     A7                      ; MS word = 0
    ||      zero    .D1     A6                      ; LS word = 0

            set     .S1     A7,30,30,A7             ; DP FP 2.0 (0x4000_0000)

            mpydp   .M2     B5:B4, B7:B6, B9:B8     ; t = arg2 * x1
    ||      extu    .S2     B5,1,21,B2              ; exp2 = 0 ?
            nop             8

            subdp   .L2x    A7:A6, B9:B8, B9:B8     ; t = 2.0 - (arg2*x1)
            nop             5

            mpydp   .M2     B7:B6, B9:B8, B7:B6     ; x2 = x1*(2-arg2*x1)
            nop             8

            mpydp   .M2     B5:B4, B7:B6, B9:B8     ; t = arg2 * x2
            nop             8

            subdp   .L2x    A7:A6, B9:B8, B9:B8     ; t = 2.0 - (arg2*x2)
            nop             5

            mpydp   .M2     B7:B6, B9:B8, B7:B6     ; x3 = x2*(2-arg2*x2)
            nop             8

            mpydp   .M2     B5:B4, B7:B6, B9:B8     ; t = arg2 * x3
            nop             8

            subdp   .L2x    A7:A6, B9:B8, B9:B8     ; t = 2.0 - (arg2*x3)
            nop             5

            mpydp   .M2     B7:B6, B9:B8, B7:B6     ; x4 = x3*(2-arg2*x3)
            nop             8

      [B2]  mpydp   .M1x    A5:A4, B7:B6, A5:A4     ; ans = arg1 * x4
    ||[!B2] set     .S1     A5,0,30,A5              ; exp/mant = all 1s (exp2=0)    
    ||[!B2] or      .L1     -1,A4,A4                ; lower mantissa = all 1s

            nop             3
            b       .S2     b3                      ; normal function return
            nop             5                       ; wait for ans in reg. pair

            .end
    ;-----------------End of DIVDP0.asm-----------------------------------------

    * ======================================================================== *
    *  End of file: divdp.asm                                                  *
    * ======================================================================== *

  • Hi Yimin,

    I'm sorry that it has taken me so long to get back to working on this. I made the change from your last comment and it does work. I understand the change and I suppose I will need to modify all of the other MATHLIB-RTS assembly files to add ELF symbols (at least until there is a new MATHLIB release with this big fix).

    Can you confirm for me that all of the ELF library symbols are the same as the COFF symbols but with the "__c6xabi_" prefix? Are there any exceptions to this rule that I will need to know about?

    Thanks,
    Dave
  • Hi Dave,

    I don't think you need to change other function names. Typically, ELF function name is the same COFF name without leading _. That's the convention we followed. This division function somehow is different. If you see other function give you similar trouble, please let me know. Thanks.

    regards,

    Yimin
  • Yimin Zhang said:

    Typically, ELF function name is the same COFF name without leading _. That's the convention we followed. This division function somehow is different.

    Hi Yimin,

    Unfortunately, I do not think that the division function is different -- it seems that the ELF (EABI) function names in the RTS library are all using the same convention as the division function. Please refer to Table 7-11 in SPRU187, "TMS320C6000 Optimizing Compiler v7.6 User's Guide," which I have reproduced a small portion of for easy reference:

    Table 7-11. Summary of Run-Time-Support Arithmetic Functions

    Type Function in COFF ABI Function in EABI Description
    double _addd (double, double) __c6xabi_addd (double, double) Double addition
    double _cmpd (double, double) __c6xabi_cmpd (double, double) Double comparison
    double _divd (double, double) __c6xabi_divd (double, double) Double division
    double _mpyd (double, double) __c6xabi_mpyd (double, double) Double multiplication
    double _subd (double, double) __c6xabi_subd (double, double) Double subtraction
    float _addf (float, float) __c6xabi_addf (float, float) Float addition
    float _cmpf (float, float) __c6xabi_cmpf (float, float) Float comparison
    float _divf (float, float) __c6xabi_divf (float, float) Float division
    float _mpyf (float, float) __c6xabi_mpyf (float, float) Float multiplication
    float _subf (float, float) __c6xabi_subf (float, float) Float subtraction
    int _divi (int, int) __c6xabi_divi (int, int) Signed integer division
    int _remi (int, int) __c6xabi_remi (int, int) Signed integer remainder
    uint _divu (uint, uint) __c6xabi_divu (uint, uint) Unsigned integer division
    uint _remu (uint, uint) __c6xabi_remu (uint, uint) Unsigned integer remainder

    In the RTS library, the "__c6xabi" prefix seems to be the convention that was used for creating ELF function names from COFF names. Therefore, I think all of the function names in the MATHLIB_RTS are incorrect (not just divd).

    Is there any hope of having a MATHLIB_RTS release with this bug fix in the near future so that I do not need to change all of the function names by hand?

    Thanks again,
    Dave

  • Hi Dave,

    The functions you listed above are not in MATHLIB. I reviewed all global symbol names in ELF library. All other function names should be fine, except recip. I did not find recip in compiler version 7.4. We need to think about what to do there in the next release. For you purpose, changing div only should be fine.

    regards,

    Yimin

  • Hello again Yimin,

    Thanks for the clarification; you are correct. However, I am seeing one more exception. The ELF library name for single-point division is __c6xabi_divf instead of _divf, so I'm pretty sure that I need to modify divsp.asm in the same way as divdp.asm. Can you please confirm this for me? Thanks!