jkmcnk / sx-gcc

The GNU Compiler Collection port to NEC SX CPU architecture.
GNU General Public License v2.0
0 stars 2 forks source link

another issue with assembler errors when compiling with "-ffunction-sections -fdata-sections" flags enabled. #141

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
This issue is very similar to issue #135.

If we try to compile the example below with the "-ffunction-sections
-fdata-sections" gcc flags enabled, we get assembler errors:

{{{

#include <string>

void test01(void)
{
  const std::string str_01("point bolivar, texas");
  char str_lit01[] = "point bolivar, texas";
  std::string str03;
  std::string str05;

  const int len1 = sizeof(str_lit01)/sizeof(char);
  str05.append(str03.begin(), str03.end());
}

int main()
{ 
  test01();
  return 0;
}

}}}

The assembler errors are, as follows:

/tmp/ccDgHJpg.s:209: Error: can't resolve `.text' {.text section} -
`.LK._Z6test01v' {.text._Z6test01v section}
/tmp/ccDgHJpg.s:211: Error: can't resolve `.text' {.text section} -
`.LK._Z6test01v' {.text._Z6test01v section}
/tmp/ccDgHJpg.s:213: Error: can't resolve `.text' {.text section} -
`.LK._Z6test01v' {.text._Z6test01v section}
/tmp/ccDgHJpg.s:215: Error: can't resolve `.text' {.text section} -
`.LK._Z6test01v' {.text._Z6test01v section}

Because of this issue, a couple of libstdc++ testcases fail (one of such
testcases is
"libstdc++-v3/testsuite/21_strings/char_traits/requirements/char/1.cc").

Original issue reported on code.google.com by nou...@gmail.com on 14 Jul 2009 at 2:52

GoogleCodeExporter commented 8 years ago
Humm interesting fact: if we change one of the "point bolivar, texas" strings to
"point bolivar, texas TEST":

{{{

#include <string>

void test01(void)
{
  const std::string str_01("point bolivar, texas TEST");
  char str_lit01[] = "point bolivar, texas";
  std::string str03;
  std::string str05;

  const int len1 = sizeof(str_lit01)/sizeof(char);
  str05.append(str03.begin(), str03.end());
}

int main()
{ 
  test01();
  return 0;
}

}}}

The code compiles fine...

Original comment by nou...@gmail.com on 14 Jul 2009 at 2:58

GoogleCodeExporter commented 8 years ago
If we check the assembler code of the second example (i.e. the one that compiles
successfully), we can see the following lines, among others:

{{{
    text
    align   16
.LC3:
    str     "point bolivar, texas TEST\000"
    section .text._Z6test01v, "xr"
    align   16
.LC7:
    str     "point bolivar, texas\000"
}}}

On the other hand, if we check the assembler code of the first example (i.e. 
the one
that fails to compile), there is only one definition of the string constant: 

{{{
    text
    align   16
.LC3:
    str     "point bolivar, texas\000"
    section .text._Z6test01v, "xr"
}}}

The constant is defined only in the ".text" section! There is of course nothing 
wrong
with defining the constant value only once, the problem is because we try to 
access
that value directly from a different section. This triggers the assembler error.

Original comment by nou...@gmail.com on 14 Jul 2009 at 3:12

GoogleCodeExporter commented 8 years ago
Another interesting fact: the "const std::string str_01("point bolivar, texas");
" generates an assembly code which compiles correctly. This code references the
"point bolivar, texas\000" value indirectly: first, it loads the address of the 
value
which is then used to reference the value. 

So, replacing the direct referencing of the constant value which is located in a
different section with indirect referencing would solve the problem.

Original comment by nou...@gmail.com on 14 Jul 2009 at 3:29

GoogleCodeExporter commented 8 years ago

Original comment by jmoc...@gmail.com on 9 Oct 2009 at 9:23