Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
GoogleCodeExporter opened this issue May 5, 2016 · 4 comments

Comments

@GoogleCodeExporter
Copy link

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 [email protected] on 14 Jul 2009 at 2:52

@GoogleCodeExporter
Copy link
Author

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 [email protected] on 14 Jul 2009 at 2:58

@GoogleCodeExporter
Copy link
Author

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 [email protected] on 14 Jul 2009 at 3:12

@GoogleCodeExporter
Copy link
Author

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 [email protected] on 14 Jul 2009 at 3:29

@GoogleCodeExporter
Copy link
Author

Original comment by [email protected] on 9 Oct 2009 at 9:23

  • Added labels: Priority-Critical
  • Removed labels: Priority-Medium

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant