Skip to content

Warn when --version-script has no effect - #1587

Open
Rachit Mehta (rachitmeht) wants to merge 1 commit into
qualcomm:mainfrom
rachitmeht:fix-version_script-warning-1444
Open

Warn when --version-script has no effect#1587
Rachit Mehta (rachitmeht) wants to merge 1 commit into
qualcomm:mainfrom
rachitmeht:fix-version_script-warning-1444

Conversation

@rachitmeht

Copy link
Copy Markdown

Version scripts control symbol visibility in the dynamic symbol table (.dynsym). When output types don't create .dynsym, version scripts are silently ignored, So, analyzed when .dynsym is created: isShared() || isPIE() || (isStatic() && forceDynamic())

Negated these conditions to warn when version scripts have no effect:

  • Static executable: isCodeStatic() && !isPIE() && !forceDynamic()
  • Relocatable output: isLinkPartial() (in this case also no .dynsym is created)

Implemented in ObjectLinker::parseVersionScript() after version script is recorded but before parsing.

Changes:

  • DiagLDScript.inc: Added 2 warning diagnostics
  • ObjectLinker.cpp: Added warning checks
  • VersionScriptNoEffect.test: 6 test cases

Resolves #1444

Emit warnings when version scripts are specified but will be ignored
because no dynamic symbol table (.dynsym) will be created.

Warns in these cases:
- Static executable (without -pie or --force-dynamic)
- Relocatable output (-r)

No warning for PIE executables, shared libraries, or static executables
with --force-dynamic, as these correctly have effect of version-script.

Adds test coverage in VersionScriptNoEffect.test with 6 test cases.

Resolves qualcomm#1444

Signed-off-by: Rachit Mehta <rachmeht@qti.qualcomm.com>
@rachitmeht
Rachit Mehta (rachitmeht) force-pushed the fix-version_script-warning-1444 branch from 9351ccd to f9337dd Compare August 4, 2026 04:57
@@ -0,0 +1,34 @@
# Test that version scripts emit warnings when they have no effect
# (i.e., when no dynamic symbol table will be created)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit : use the test format for new tests.

if (ThisConfig.isLinkPartial()) {
// Relocatable output (-r) never emits .dynsym.
ThisConfig.raise(Diag::warn_version_script_no_effect_relocatable)
<< VersionScriptInput->decoratedPath();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should this be a warning under -Wlinker-script category ?

# RUN 4: Shared library should NOT warn (has .dynsym)
RUN: %link %linkopts -shared --version-script=%p/Inputs/vs1 -o %t_shared.so %t1_pic.o 2>&1 | %filecheck --allow-empty --check-prefix=NO-WARN-SHARED %s

NO-WARN-SHARED-NOT: warning: version script has no effect

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

no version script filename is printed ?

what about if you have a linker script that has a version block ?

"emit a dynamic symbol table")
DIAG(warn_version_script_no_effect_relocatable, DiagnosticEngine::Warning,
"%0: warning: version script has no effect: relocatable output (-r) does "
"not emit a dynamic symbol table")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

do we need does not emit a dynamic symbol table ? remove the reason ?

"Error parsing version script %0")
DIAG(warn_version_script_no_dynsym, DiagnosticEngine::Warning,
"%0: warning: version script has no effect: static executable does not "
"emit a dynamic symbol table")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

not sure about static executables and version script. We should check

ld.eld <object> .... <object> -static -pie

# RUN 6: Verify the warnings include the version script path
RUN: %link %linkopts -static --entry=main --version-script=%p/Inputs/vs1 -o %t_path.out %t1.o 2>&1 | %filecheck --check-prefix=CHECK-PATH %s

CHECK-PATH: {{.*}}/Inputs/vs1: warning: version script has no effect

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

will this test pass on windows ?

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.

Report warning if a version script is used in cases where it is not meaningful

4 participants