https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118716
Bug ID: 118716
Summary: GCC(11.2) generating newer symbol for
std::string::compare while linking against older
runtime(libstdc++ : 6.0.13)
Product: gcc
Version: 11.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: rayatha1 at in dot ibm.com
Target Milestone: ---
Background: We have an agent code which was previously compiled with GCC 4.4.7
using libc 2.12 and libstdc++ : 6.0.13 and are planning to upgrade it to GCC
11.2. However to maintain backward Compatibility we would like to link against
older c/c++ runtime with GCC 11.2.
Environment:
Red Hat Enterprise Linux Server release 6.10 (Santiago)
$g++ --version
g++ (GCC) 11.2.0
$ldd --version
ldd (GNU libc) 2.12
$ls -lrt /usr/lib64 | grep libstdc++
libstdc++.so.6.0.13
Sample Code:
#include <string>
#include <iostream>
int main() {
std::string foo = "apple";
std::string bar = "banana";
if(foo.compare(bar) == 0){
std::cout<<"Equal"<<std::endl;
}
else
std::cout<<"Not Equal"<<std::endl;
}
Command:
$ g++ -Os -std=c++03 -nostdinc++ -I/usr/include/c++/4.4.7
-I/usr/include/c++/4.4.7/i686-redhat-linux -L/usr/lib64 -Wl,-rpath,/usr/lib64
-o compare compare.cpp
$ ./compare
./compare: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.16' not found
(required by ./compare)
$ objdump -T compare | grep compare
compare: file format elf64-x86-64
0000000000000000 DF *UND* 0000000000000000 (GLIBCXX_3.4.16)
_ZNSs10_S_compareEmm
>From older Environment where issue is not seen:
$g++ --version
g++ (GCC) 4.4.7 20120313 (Red Hat 4.4.7-23)
$ldd --version
ldd (GNU libc) 2.12
$objdump -T compare | grep compare
compare: file format elf64-x86-64
0000000000000000 DF *UND* 0000000000000000 (GLIBCXX_3.4)
_ZNKSs7compareERKSs
I've tested different versions, and the generation of new
symbol(GLIBCXX_3.4.16) _ZNSs10_S_compareEmm) started from GCC-10.3 while the
older GCC generates symbol(_ZNKSs7compareERKSs) with optimisation in place(-Os)
GCC 4.4.7 => No issue
GCC 7.5 => No issue
GCC 9.3 => No issue
GCC-10.3 => Issue started
GCC-11.2 => Issue