-
Notifications
You must be signed in to change notification settings - Fork 75
Warn when --version-script has no effect #1587
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -65,6 +65,12 @@ DIAG(reading_dynamic_list, DiagnosticEngine::Verbose, "Dynamic List[%0] : %1") | |
| DIAG(reading_extern_list, DiagnosticEngine::Verbose, "Extern List[%0] : %1") | ||
| DIAG(error_parsing_version_script, DiagnosticEngine::Error, | ||
| "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") | ||
| 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") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ? |
||
| DIAG(fatal_divide_by_zero, DiagnosticEngine::Fatal, | ||
| "%0: division by zero in expression %1") | ||
| DIAG(fatal_modulo_by_zero, DiagnosticEngine::Fatal, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -367,6 +367,18 @@ bool ObjectLinker::parseVersionScript() { | |
| // Record the dynamic list script in the Map file. | ||
| if (layoutInfo) | ||
| layoutInfo->recordVersionScript(List); | ||
| // Warn if the version script will have no effect because no dynamic | ||
| // symbol table will be emitted. | ||
| if (ThisConfig.isLinkPartial()) { | ||
| // Relocatable output (-r) never emits .dynsym. | ||
| ThisConfig.raise(Diag::warn_version_script_no_effect_relocatable) | ||
| << VersionScriptInput->decoratedPath(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be a warning under -Wlinker-script category ? |
||
| } else if (ThisConfig.isCodeStatic() && !ThisConfig.options().isPIE() && | ||
| !ThisConfig.options().forceDynamic()) { | ||
| // Static executable without PIE or --force-dynamic doesn't emit .dynsym. | ||
| ThisConfig.raise(Diag::warn_version_script_no_dynsym) | ||
| << VersionScriptInput->decoratedPath(); | ||
| } | ||
| // Read the dynamic List file | ||
| ScriptFile VersionScriptReader( | ||
| ScriptFile::VersionScript, *ThisModule, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit : use the test format for new tests. |
||
|
|
||
| # RUN 1: Static executable should warn | ||
| RUN: %clang %clangopts -c -O2 %p/Inputs/1.c -o %t1.o | ||
| RUN: %link %linkopts -static --entry=main --version-script=%p/Inputs/vs1 -o %t_static.out %t1.o 2>&1 | %filecheck --check-prefix=WARN-STATIC %s | ||
|
|
||
| WARN-STATIC: warning: version script has no effect: static executable does not emit a dynamic symbol table | ||
|
|
||
| # RUN 2: Relocatable output should warn | ||
| RUN: %link %linkopts -r --version-script=%p/Inputs/vs1 -o %t_reloc.o %t1.o 2>&1 | %filecheck --check-prefix=WARN-RELOC %s | ||
|
|
||
| WARN-RELOC: warning: version script has no effect: relocatable output (-r) does not emit a dynamic symbol table | ||
|
|
||
| # RUN 3: PIE executable should NOT warn (has .dynsym) | ||
| RUN: %clang %clangopts -c -fpic -O2 %p/Inputs/1.c -o %t1_pic.o | ||
| RUN: %link %linkopts -pie --entry=main --version-script=%p/Inputs/vs1 -o %t_pie.out %t1_pic.o 2>&1 | %filecheck --allow-empty --check-prefix=NO-WARN-PIE %s | ||
|
|
||
| NO-WARN-PIE-NOT: warning: version script has no effect | ||
|
|
||
| # 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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ? |
||
|
|
||
| # RUN 5: Static with --force-dynamic should NOT warn (forces .dynsym) | ||
| RUN: %link %linkopts -static --force-dynamic --entry=main --version-script=%p/Inputs/vs1 -o %t_force.out %t1.o 2>&1 | %filecheck --allow-empty --check-prefix=NO-WARN-FORCE %s | ||
|
|
||
| NO-WARN-FORCE-NOT: warning: version script has no effect | ||
|
|
||
| # 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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will this test pass on windows ? |
||
There was a problem hiding this comment.
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