RFC: Don't output symbol version requirement for non-DT_NEEDED libs
Commit Message
On Sun, Nov 30, 2014 at 7:50 PM, Alan Modra <amodra@gmail.com> wrote:
> On Fri, Nov 28, 2014 at 10:27:26AM -0500, Carlos O'Donell wrote:
>> On 11/27/2014 07:06 PM, Joseph Myers wrote:
>> > Actually, I think it's a linker bug not a glibc bug. If you don't link
>> > with a library providing a symbol you use, I don't think any information
>> > at all about how it might be resolved with some library you didn't link
>> > against should be embedded in the binary: not a DT_NEEDED entry, and not a
>> > version requirement. I don't think you can presume at static link time,
>> > with a weak undefined symbol like that, "this symbol isn't needed, but if
>> > defined at runtime it must have this version" (as opposed to "this symbol
>> > isn't needed, and might have any version at runtime", which is the safe
>> > assumption).
>>
>> I had not considered it like that. I agree with your rationale.
>>
>> In which case this is clearly a bug in binutils and Alan's patch
>> is correct.
>>
>> I tried to come up with a case where this would matter, but from
>> first principles I couldn't construct any sensible test cases.
>
> If the version *does* matter, then mentioning on the command line
> the library that defines the symbol will result in both the symbol
> being versioned and the library in DT_NEEDED.
>
> I've gone ahead and committed the linker patch, to 2.25 too. Thanks
> to all who contributed to this thread.
>
I checked this testcase into master and 2.25 branch.
@@ -1,3 +1,16 @@
+2014-12-01 H.J. Lu <hongjiu.lu@intel.com>
+
+ PR ld/16452
+ PR ld/16457
+ * ld-elf/pr16452.map: New file.
+ * ld-elf/pr16452.od: Likewise.
+ * ld-elf/pr16452a.c: Likewise.
+ * ld-elf/pr16452b.c: Likewise.
+ * ld-elf/pr16457.od: Likewise.
+
+ * ld-elf/shared.exp (build_tests): Add tests for PR ld/16452 and
+ PR ld/16457.
+
2014-11-27 H.J. Lu <hongjiu.lu@intel.com>
* ld-mips-elf/got-vers-1.rd: Add symbol version string to
new file mode 100644
@@ -0,0 +1 @@
+FOO{global:f;};
new file mode 100644
@@ -0,0 +1,7 @@
+#failif
+#...
+Version References:
+#...
+ required from libpr16452a.so:
+ 0x[0-9a-f]+ 0x00 .. FOO
+#...
new file mode 100644
@@ -0,0 +1 @@
+int f(void){return 0;}
new file mode 100644
@@ -0,0 +1,2 @@
+int f(void) __attribute__((weak));
+int main(void){return f?f():0;}
new file mode 100644
@@ -0,0 +1,6 @@
+#failif
+#...
+Dynamic Section:
+#...
+[ ]+NEEDED[ ]+libpr16452a.so
+#...
@@ -255,6 +255,18 @@ set build_tests {
{"Build libpr16496b.so"
"-shared tmpdir/pr16496b.o tmpdir/libpr16496a.so" ""
{dummy.c} {{objdump {-R} pr16496b.od}} "libpr16496b.so"}
+ {"Build libpr16452a.so"
+ "-shared -Wl,-soname,libpr16452a.so,--version-script=pr16452.map" "-fPIC"
+ {pr16452a.c} {} "libpr16452a.so"}
+ {"Build libpr16452b.so"
+ "-shared -Wl,-soname,libpr16452b.so,--no-as-needed
tmpdir/libpr16452a.so" "-fPIC"
+ {dummy.c} {} "libpr16452b.so"}
+ {"Build pr16452"
+ "tmpdir/libpr16452b.so -Wl,-rpath=tmpdir" ""
+ {pr16452b.c} {{objdump {-p} pr16452.od}} "pr16452"}
+ {"Build pr16457"
+ "tmpdir/libpr16452b.so -Wl,-rpath=tmpdir" ""
+ {pr16452b.c} {{objdump {-p} pr16457.od}} "pr16457"}
}