Tuesday, May 18, 2010

relocation truncated to fit: R_X86_64_32S against `.bss' Error

"relocation truncated to fit: R_X86_64_32S against `.bss' Error"
This is a rare error but when you get it there is no way you can get out of it without doing something fancy. If you do an exhaustive search you will find people trying to upgrade their linkers as the issue is definitely with linker. People even tried rebuilding their linker to ignore the relocation errors. Even if you do that you will SEGFAULT at run time.

The reason for this error is the size of data that you are using. This is seen to happen when your program needs more than 2GB of data. Well, who needs such big data at compile time? I do for one and there are other people in the HPC world who do that too. For all of them the life saver or may be a day saver is the compiler option -mcmodel.

All you need to do is to compile your program with

-mcmodel medium option.

For example, I was working with STREAM benchmarking tool from university of Virginia and had this error. To rectify this, I compiled my program with following command:

 gcc -mcmodel=medium stream.c -o stream

I have removed additional flags for the sake of simplicity. You might want to use various flags for your program. Please comment if this was helpful.

75 comments:

  1. Yep. This solution worked for me. Thanks for sharing.

    ReplyDelete
  2. Dude, You are a scholar and a gentleman! This worked perfectly!

    ReplyDelete
  3. Dear Anony,
    Thank you for those nice words. I am glad to be of some help.

    Regards,
    Dinesh

    ReplyDelete
  4. Man, this is great!!!. Please forgive my naive questions, what's the equivalent flag for fortran (intel compiler ifort), and what does mcmodel do exactly? (I know that it gives the program more memory but how?).

    ReplyDelete
  5. Forget about the last comment, I got it. I had the flags in a wrong part of my makefile.

    ReplyDelete
  6. Hi,

    Just wanted to say that this worked for me also.

    Thank you very much

    ReplyDelete
  7. Dear Anony,
    I am glad I was of some help.

    Regards,
    Programmer

    ReplyDelete
  8. this worked for me as well, thank you very much :)

    ReplyDelete
  9. @Anony,

    I appreciate your taking time to leave a reply.

    Regards,
    Programmer

    ReplyDelete
  10. So Beautiful. Thanks a lot Guys. Worked perfectly for me.

    ReplyDelete
  11. Thanks Dear. Little did I know this post will help so many people. I am glad I could be of some help.

    ReplyDelete
  12. I have a warning:

    /tmp/cciXCDL1.s: Assembler messages:
    /tmp/cciXCDL1.s:3: Warning: ignoring incorrect section type for .lbss

    does anyone knows why?

    ReplyDelete
  13. thanks a bunch...it worked for me

    ReplyDelete
  14. Dear Dinesh,
    It worked for me!!! I am very grateful. THANK YOU!
    Antonio

    ReplyDelete
  15. Dear Antonio,

    I am glad it worked for you. I am going back to work on large data soon. Hopefully, this will come handy for me too.

    Regards,
    Programmer

    ReplyDelete
  16. Thanks for sharing. Although my 64bit kernel still needed a large model, your post pointed out for the solution.
    Best wishes,
    Alex

    ReplyDelete
  17. I got the same error but I am compiling program in fortran. May you tell me how do you modify the compiler in case of fortran please?

    ReplyDelete
  18. Dear ND,

    As far as I knew this option worked for both compilers, especially if we are talking about intel compilers.

    You can find more information on http://www.ualberta.ca/CNS/RESEARCH/LinuxClusters/64-bit.html

    Hope that helps.

    Regards,
    Dinesh

    ReplyDelete
  19. It worked for me, too :-)

    Heidi

    ReplyDelete
  20. thank you very much for this post... :)

    ReplyDelete
  21. Dear Readers,

    Thank you for taking time to leave feedback. It is much appreciated.

    Regards,
    Dinesh

    ReplyDelete
  22. worked with the gfortran compiler.... many thanks

    added -mcmodel=medium

    so my compile command was:
    gfortran -mcmodel=medium -o a.out interp_GeoidEGM2008_Envisat.f

    ReplyDelete
  23. Work with 64bit ifort 11.159/75 & 12.1.32 on rhel5 and SL6, but need -shared-intel to compile correctly.

    Strange thing, the same code compile without this option on ifort 12 for OSX

    ReplyDelete
  24. Thank you guys for taking time to leave a comment. Much appreciated.

    ReplyDelete
  25. Thanks a lot you just saved my evening... I just didn't get why that creepy matrix didn't allocate...

    ReplyDelete
  26. Thanks a lot, saved me a lot of time today

    ReplyDelete
  27. thanks a lot...you saved me a lot of time

    ReplyDelete
  28. I had the same problem. I compiled it having mcmodel=medium. However, when i run the *.exe, i get a message that zsh : Killed a.f90. Can anyone help me solve this problem

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
    2. Thanks a lot, it work for me too ;)

      Delete
  29. Works perfect :) thanx

    ReplyDelete
  30. Grateful, thanks! It helped me compile my fortran code...

    ReplyDelete
  31. wow thanks! Had this problem for a couple of days and decided to Google it. Your site came up first. A life saver!

    ReplyDelete
  32. I was always using the mcmodel=medium flag while compiling and there were no issues. However, now with gfortran I get the same error and with intel it is all fine.

    gfortran -mcmodel=medium -J mod_s0 -o c.x c.F
    /tmp/cc6Vmggd.s: Assembler messages:
    /tmp/cc6Vmggd.s:40: Warning: ignoring incorrect section type for .

    I appreciate any suggestions

    ReplyDelete
  33. Warning: ignoring incorrect section type for .lbss

    This I got rid of by using -mcmodel=large instead of -mcmodel=medium. This is with gfortran!! strange when it works fine with the latter in intel.

    ReplyDelete
  34. Hi,

    I was getting same error when using gfortran, and I used -mcmodel=medium and now the code compiles fine. However at run time, I get Segmentation fault error. Any suggestion on this?

    Thanks!

    ReplyDelete
  35. Thank you for the tip. It worked also with pgf compiler

    ReplyDelete
  36. Thanks a lot friend. It worked perfectly.

    ReplyDelete
  37. Nice post... thank you so much

    ReplyDelete
  38. I am using fortran in two different computers, in one worked your command but in the other one no at all!

    ReplyDelete
  39. Thanks, man, that helped! Worked with gfortran/gcc version 4.6.3

    Mikhail

    ReplyDelete
  40. Same problems here, got compiled successfully with
    -mcmodel=medium
    but when running the program, got error message:
    Killed

    Anyone can help me?

    ReplyDelete
  41. Hi,
    I got this this error("relocation truncated to fit: R_X86_64_32S against `.bss' Error") in gfortan, when i was running the following make file, even after using the option -mcmodel=medium

    makefile contents

    FC = gfortran

    OBJINV = wsinv3d.o iodata.o util.o setupop.o mcov.o fwd3d.o\
    solve3d.o fwd2d.o fwd1d.o divcorr.o sens3d.o representer.o search.o\
    blas1.o blas2_3.o LAPACK_C16.o LAPACK_R8.o


    wsinv3d : $(OBJINV)
    $(FC) -mcmodel=medium -O3 -g $(OBJINV) -o wsinv3dmt


    $(OBJINV): para.h

    Kindly help me
    I appreciate any suggestions
    Thanks

    Chinna Reddy

    ReplyDelete
  42. Thank you Dinesh. Your post was super awesome

    ReplyDelete
  43. Thanks so much. It helped me a lot.

    ReplyDelete
  44. this also helped me to compile my program

    Thanks a ton

    ReplyDelete
  45. Thanks a ton man...this worked perfectly well.
    By the way I tried the same, -mcmodel=medium with a lower config pc, and it just killed the program. Any inputs?

    ReplyDelete
  46. This worked for us. Thanks for the help!

    ReplyDelete
  47. Thanks for sharing this.

    A Seismology student.

    ReplyDelete
  48. Thanks a lot, It helped me a lot.

    ReplyDelete
  49. "life saver" works!! Thank you very much!! :D

    ReplyDelete
  50. Thanks... it gave my life back.

    ReplyDelete
  51. omg! u r true life saver! thanks a lot!

    ReplyDelete
  52. Thank you very much for this advice !

    ReplyDelete
  53. I was using intel compilers.
    Adding -mcmodel=medium worked for me. Thank you so much.

    ReplyDelete
  54. Thank you very much for sharing this usefull piece of information!

    ReplyDelete
  55. Thanks for your help !

    ReplyDelete
  56. wow thanks a lot. It works for me

    ReplyDelete
  57. Great!!! This solve my program issue.
    Thanks!!!!

    ReplyDelete
  58. what is the header file that is to be used ?

    ReplyDelete
  59. Hi! Thanks a lot for taking the time to put this entry! It is really helping people! :D

    Thanks and good luck!

    ReplyDelete
  60. I have a filename- eof_surfacetemperature.f
    I am trying to compile this program using ifort -mkl eofsurfacetemperature.f command.
    Can you please tell me how to combine -mcmodel=medium option in this command as I am seeing the error : relocation truncated to fit R_X86_64_32

    ReplyDelete
  61. It worked for my file. Wow!!. Thank you very much.

    ReplyDelete
  62. Thanks you so much because the information is very useful for me. tuyen dung digital marketing manager o tphcm

    ReplyDelete