Skip to content

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

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

Warn when --version-script has no effect#1587
Rachit Mehta (rachitmeht) wants to merge 2 commits 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

@@ -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.

Comment thread lib/Object/ObjectLinker.cpp Outdated
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 ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yes, it should, but there is -Wversion-script also ( not documented ), should it be warning under both 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 ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I think, the case of version block in linkerscript will be solved automatically if this PR #1672 is correct. Otherwise we have to add same check in two different paths.

"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 ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

removed.

"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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Verified: static pie do have .dynsym table but it doesn't contain any user defined symbols, so, version-script has no effect on it. We should warn in this case also.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Actually, for every pie combination, it is not affected by version script.
except for -pie --export-dynamic.

# 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 ?

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 f9337dd to b5769bc Compare August 13, 2026 11:15
Version scripts control symbol visibility in .dynsym, but have no effect
when no user symbols are exported. Add warning for:
- PIE links: symbols suppressed unless --export-dynamic overrides
- Static/relocatable: no .dynsym unless --force-dynamic

Warning fires at version script parse time, guarded by -Wlinker-script.

Resolves qualcomm#1444
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