Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions include/eld/Diagnostics/DiagLDScript.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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")

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

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 ?

DIAG(fatal_divide_by_zero, DiagnosticEngine::Fatal,
"%0: division by zero in expression %1")
DIAG(fatal_modulo_by_zero, DiagnosticEngine::Fatal,
Expand Down
12 changes: 12 additions & 0 deletions lib/Object/ObjectLinker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

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 ?

} 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,
Expand Down
34 changes: 34 additions & 0 deletions test/Common/standalone/VersionScript/VersionScriptNoEffect.test
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)

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.


# 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

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 ?


# 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

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 ?

Loading