Open GoogleCodeExporter opened 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
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
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
Original comment by jmoc...@gmail.com
on 9 Oct 2009 at 9:23
Original issue reported on code.google.com by
nou...@gmail.com
on 14 Jul 2009 at 2:52