Skip to content

Conversation

@zhangzikang01
Copy link

Signed-off-by: zhangzikang01 zhangzikang@kylinos.cn

Comparison of the librelp-1.2.16 version reveals that the librelp.so.0 library generated by compiling the current version of the source code no longer includes the relpEngineGetVersion symbol, which does not meet compatibility requirements. Therefore, an analysis of the source code was conducted.

The analysis found that in the Makefile.am file, "AM_CFLAGS=-fvisibility=hidden" was added, setting the default attribute to hidden. Then, during function definition, the attribute was modified to default via "attribute((visibility("default")))". However, modifying the attribute to default at the definition location of the relpEngineGetVersion function did not take effect. The relpEngineGetVersion function retained the hidden attribute, resulting in the absence of the relpEngineGetVersion symbol in the compiled librelp.so.0 library.

Consult the information in the following link:
https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html

The material indicates that for functions, the attribute should be placed either before the declaration type or at the very end of the function.

A test demo was written to verify the usage of attribute:

#include <stdio.h>

#define PART_OF_API attribute((visibility("default")))
#define VERSION "1.11.0"
#define CH 't'

const char * test_0(void)
{
return (char*) (VERSION);
}

const char * PART_OF_API test_1(void)
{
return (char*) (VERSION);
}

PART_OF_API const char * test_2(void)
{
return (char*) (VERSION);
}

void main()
{
printf("test!\n");
}

gcc -fvisibility=hidden test.c -o libtest.o

test.c:13:1: warning: the 'visibility' attribute is ignored on a non-class type [-Wattributes]
13 | {
| ^

readelf -sW libtest.o | grep test_

70: 0000000000400690    12 FUNC    GLOBAL HIDDEN    13 test_1
81: 000000000040069c    12 FUNC    GLOBAL DEFAULT   13 test_2
86: 0000000000400684    12 FUNC    GLOBAL HIDDEN    13 test_0

Based on the test results, it was found that:

(1) Without adding attribute((visibility("default"))): the attribute remains hidden.
(2) Adding attribute((visibility("default"))) before the declaration type: the attribute is successfully modified to default.
(3) Adding attribute((visibility("default"))) between the declaration type and the function name: the attribute modification does not take effect, remains hidden, and a warning is generated (though warning messages are suppressed in the source code: #pragma GCC diagnostic ignored "-Wattributes").

Therefore, it is preliminarily determined that the incorrect placement of attribute((visibility("default"))) caused the attribute modification to fail. Hence, this PR is submitted to address the issue.

@gemini-code-assist
Copy link

Summary of Changes

Hello @zhangzikang01, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves a critical compatibility issue in the librelp library where several API functions, notably relpEngineGetVersion, were unintentionally hidden due to incorrect placement of GCC's __attribute__((visibility("default"))) directive. The changes involve systematically repositioning this attribute to ensure proper symbol export, thereby restoring expected library functionality and preventing future regressions related to symbol visibility.

Highlights

  • Symbol Visibility Fix: Corrected the placement of the __attribute__((visibility("default"))) directive for numerous API functions across src/relp.c, src/relpclt.c, and src/relpsrv.c to ensure they are properly exported in the librelp.so.0 shared library.
  • Compatibility Restoration: This change specifically addresses a regression where the relpEngineGetVersion symbol was missing from the compiled library, thereby restoring compatibility with previous versions that expected this symbol to be available.
  • Standardized Attribute Placement: The PART_OF_API macro, which defines the visibility attribute, has been consistently moved from after the function's return type to before it, aligning with GCC's recommended usage for function attributes.
  • Removed Warning Suppression: The #pragma GCC diagnostic ignored "-Wattributes" directive, which was suppressing warnings about incorrect attribute usage for relpEngineGetVersion, has been removed, allowing the compiler to correctly flag such issues in the future.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request correctly addresses an issue with GCC attribute usage for symbol visibility. The analysis in the description is thorough and the fix is applied consistently across the codebase. By moving the PART_OF_API macro before the return type in function definitions, you've ensured that the functions are correctly exported in the shared library, which is crucial for compatibility. The removal of the pragma to suppress attribute warnings is also a good cleanup, as the root cause of the warning is now fixed. I've added one minor style suggestion for consistency.

@rgerhards rgerhards self-assigned this Jan 8, 2026
Signed-off-by: zhangzikang01 <zhangzikang@kylinos.cn>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants