All Products
Search
Document Center

Alibaba Cloud Linux:Compatibility between the GCC or Glibc versions on Alibaba Cloud Linux 3 and CentOS 8

Last Updated:Aug 14, 2024

GNU Compiler Collection (GCC) 10 and Glibc 2.28 incorporate important changes compared with GCC 8 and Glibc 2.32. The changes affect the forward or backward compatibility of GCC 10 and Glibc 2.28. This topic describes the compatibility between the GCC versions and between the Glibc versions. This topic also describes how to mitigate the impacts.

Background information

The compatibility between the GCC or Glibc versions can be classified into Application Binary Interface (ABI) compatibility and API compatibility. The ABI compatibility between the GCC or Glibc versions refers to the compatibility in which binaries can run without the need for code recompilation. The API compatibility between the GCC or Glibc versions refers to the compatibility in which application code can run unchanged without the need for code recompilation.

ABI compatibility between the GCC or Glibc versions

Note

In most cases, the GCC compiler does not involve ABI compatibility. However, operating system distributions, such as Alibaba Cloud Linux and CentOS, include the standard C++ library (libstdc++) in GCC packages. The impacts of GCC on the ABI compatibility with applications refer to the impacts of the libstdc++ library on the ABI compatibility with applications.

  • Forward compatibility: libstdc++ and Glibc are highly forward-compatible. Most of the components that are compiled on GCC 8 and Glibc 2.28 on CentOS can run in GCC 10 and Glibc 2.32 environments, respectively, on Alibaba Cloud Linux 3 without the need for code compilation.

  • Backward compatibility: libstdc++ and Glibc are not backward-compatible. The components that are compiled on GCC 10 and Glibc 2.32 on Alibaba Cloud Linux 3 cannot run unchanged in GCC 8 and Glibc 2.32 environments, respectively, on CentOS 8.

API compatibility between the GCC or Glibc versions

GCC and Glibc are core toolchain components of operating systems and are highly backward-compatible and forward-compatible with APIs. However, during version updates, changes that affect API compatibility may be made to GCC and Glibc.

  • GCC

    • Example of changes that affect forward API compatibility: The compilation parameters that are used in early GCC versions are deprecated in later GCC versions. As a result, you cannot compile applications that use the compilation parameters by using later GCC versions. To use later GCC versions to compile the applications, you must modify the compilation parameters for the applications.

    • Example of changes that affect backward API compatibility: New compilation parameters are introduced in later GCC versions. As a result, you cannot compile applications that use the new compilation parameters by using early GCC versions. To use early GCC versions to compile the applications, you must modify the compilation parameters for the applications.

  • Glibc

    • Example of changes that affect forward API compatibility: Functions or header files that are used in early Glibc versions are deprecated in later Glibc versions. As a result, you cannot compile applications that use the functions or header files by using later Glibc versions. To use later Glibc versions to compile the applications, you must modify the application code.

    • Example of changes that affect backward API compatibility: New functions and implementations are introduced in later Glibc versions. As a result, you cannot compile applications that use the new functions by using early Glibc versions. To use early Glibc versions to compile the applications, you must modify the application code.

Changes in Glibc 2.32 and impacts of the changes

The following table describes the important changes in Glibc 2.28 compared with Glibc 2.32, the impacts of the changes, and how to mitigate the impacts.

Type

Change

Compatibility type

Impact

How to mitigate the impacts

time

The stime function is no longer declared in the time.h header file.

API

If the stime function is used in the source code, a compilation error occurs.

Use the clock_settime function instead of the stime function.

The ftime function is deprecated.

API

If the ftime function is used in the source code, a compilation error occurs.

Use the clock_gettime function instead of the ftime function.

The gettimeofday function no longer reports information about the time zone.

API

The gettimeofday function cannot obtain information about the time zone.

Use the clock_gettime function instead of the gettimeofday function.

The settimeofday function is labeled by POSIX as obsolete.

API

The settimeofday function cannot configure the time and the time drift at the same time.

Use the clock_settime and adjtime functions instead of the settimeofday function.

The nanosleep user-mode interface uses the clock_nanosleep system call instead of the nanosleep system call.

API

If an application runs in seccomp mode and the clock_nanosleep function is not added to the seccomp whitelist, the application cannot call the nanosleep function.

Add the clock_nanosleep to the seccomp whitelist.

sysctl

The sys/sysctl.h header file is removed.

API

The code that references the header file cannot be compiled.

Delete the reference to the sys/sysctl.h header file from the code.

The sysctl function is removed and continues to exist as a compatibility symbol.

API

The sysctl system call always fails with an ENOSYS error.

Access the /proc/sys virtual process file system instead of using the sysctl interface. Use the getentropy function to obtain random bytes.

sstk

The sstk function is no longer declared in header files.

ABI

Applications that are complied on Glibc 2.28 are ABI-compatible with Glibc 2.32. If a program calls this function, the call returns a failure, which may cause unexpected behaviors in the program.

The kernel and Glibc no longer support the sstk function. Remove calls to the sstk function.

API

An error occurs if you use Glibc 2.32 to compile applications that use the sstk function.

signal

The sigmask macro and the following legacy signal handling functions are deprecated: siginterrupt, sigpause, sighold, sigrelse, sigignore, and sigset.

ABI

Binaries that are compiled on Glibc 2.28 remain ABI-compatible with libc.so.

No solution is required.

API

When you use Glibc 2.32 to compile applications that use the functions or macro, a warning or an error is returned.

Modify the source code and use the sigsuspend, sigprocmask, and sigaction functions instead.

The sys_siglist, _sys_siglist, and sys_sigabbrev functions are no longer declared in the <string.h> header file.

ABI

Binaries that are compiled on Glibc 2.28 remain ABI-compatible with libc.so.

No solution is required.

API

When you use Glibc 2.32 to compile applications that use the functions, a warning or an error is returned.

Modify the source code and use the strsignal function instead.

sys error

The sys_errlist, _sys_errlist, sys_nerr, and _sys_nerr functions are no longer declared in the stdio.h header file.

ABI

Binaries that are compiled on Glibc 2.28 remain ABI-compatible with libc.so.

No solution is required.

API

When you use Glibc 2.32 to compile applications that use the functions, a warning or an error is returned.

Use the strerror and strerror_r functions instead.

copy_file_range

The simulated implementation of the copy_file_range function is removed.

API

If the kernel does not support the copy_file_range function and an application calls the function, an ENOSYS error occurs.

If the kernel does not support the copy_file_range function, the applications must provide the functionality of the copy_file_range function. The default kernel version of Alibaba Cloud Linux 3 is 5.10, which supports the copy_file_range function.

thread

The <sys/single_threaded.h> header file, which declares the _libc_single_threaded variable, is added.

API

Using weak references to libpthread functions, such as pthread_create and pthread_key_create, to detect the singled-threaded nature of an application is an obsolete feature. Future versions of Glibc will define pthread_create in libc.so.6. As a result, such detections will always label the program as multi-threaded.

Use the _libc_single_threaded variable instead to check the singled-threaded nature of applications.

Sun RPC

Sun RPC is no longer supported.

API

Dependencies must be changed for all code that references Sun RPC header files.

  • Use the rpc/rpc.h header file provided by the libtorpc-devel package.

  • Use the rpcsvc/*.h header file provided by the rpcsvc-proto-devel package.

  • Use the rpcgen program provided by the rpcgen package.

Changes in GCC 10 and impacts of the changes

The following table describes the important changes in GCC 10 compared with GCC 8, the impacts of the changes, and how to mitigate the impacts.

Type

Change

Compatibility type

Impact

How to mitigate the impacts

-fno-common

GCC 10 defaults to the -fno-common option.

API

Multiple uninitialized duplicate global variables can be defined in the common segment.

The variables are merged and stored in the bss segment during the linking stage. Only initialized variables that have a unique name can exist the linking stage. If the -fno-common option is enabled, a linker error occurs in a program when the same global variable is defined in multiple source files of the program.

  • Make sure that the global variable is defined only in a single source file and add the extern keyword to the declaration of the variable in the other source files.

  • Enable the -fcommon option to ensure forward compatibility.

fortran

If a parameter does not match an argument, Fortran in GCC 10 reports a compilation error.

API

A compilation error occurs if parameters do not match arguments.

  • Make sure that parameters match arguments in code.

  • Degrade -fallow-argument-mismatch to warnings.

C++ header

<stdexcept> and <string> are no longer included in specific standard C++ headers.

API

Errors occur while compiling applications.

Add required header files to the applications based on the error messages.

Enumeration check

GCC 10 enforces stricter checks on enumerations and prohibits the use of enumeration elements to assign values to other enumeration elements.

API

Errors occur while compiling applications.

Use enumerations in the correct manner.

Large System Extensions (LSE)

The -moutline-atomics option is added to GCC 10 and is automatically enabled for -march=armv8-a.

API

This option is used to detect the support of AArch64 machines for LSE instructions at runtime and uses the instructions for standard atomic operations, which improves atomic concurrency.

Use this option in the correct manner. For information about other Arm64 instruction sets supported by GCC 10, see 3.19.1 AArch64 Options.

Changes to the warning options of GCC 10

The following table describes the changes to the warning options of GCC 10 compared with GCC 8.

Note

Compilation warnings do not directly affect API compatibility. If compilation warnings appear when you migrate applications to Alibaba Cloud Linux 3, we recommend that you modify the application code to suppress the warnings.

Option

Compatibility type

Change type

Description

-Waddress-of-packed-member

API

Addition

Warns that taking the address of a packed member of a struct or union results in an unaligned pointer value. By default, this option is enabled.

-Wzero-length-bounds

API

Addition

Warns about accesses to elements of zero-length array members that may overlap other members of the same object. This option is enabled by -Warray-bounds.

-Warray-bounds

API

Enhancement

Warns about out-of-bounds accesses to member arrays and accesses to elements of zero-length arrays.

-Wattribute-alias

API

Enhancement

Warns about declarations that use the alias and similar attributes whose target is incompatible with the type of the alias.

-Wformat-overflow

API

Enhancement

Warns about calls to formatted input/output functions that may overflow the destination buffer. This warning is triggered when certain or likely buffer overflow in calls to formatted output functions is detected.

-Wmissing-attributes

API

Addition

Warns when particular function attributes are missing in the aliases but not in their target.

-Wformat-truncation

API

Enhancement

Warns about calls to formatted input/output functions, such as snprintf, that may result in output truncation. This warning option works together with the -Wformat-overflow option.

-Wstringop-overflow

API

Enhancement

  • Warns about out-of-bounds stores to member arrays, including zero-length arrays, dynamically allocated objects and variable-length arrays, and instances of reads of unterminated character arrays by the built-in string functions.

  • Warns about out-of-bounds accesses by calls to user-defined functions declared by using the new attribute access.

-Wreturn-local-addr

API

Enhancement

Warns about instances of return statements returning addresses of automatic variables.

-Wrestrict

API

Enhancement

Warns about overlapping accesses to dynamically allocated objects.

-Warith-conversion

API

Enhancement

-Warith-conversion re-enables warnings from -Wconversion, -Wfloat-conversion, and -Wsign-conversion, which are automatically disabled.

References

For information about other changes in the GCC and Glibc versions, see the Release notes for Glibc and GCC.