public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* Support for automatic linking via pragma
@ 2011-02-28 18:17 Olaf van der Spek
  2011-03-04 16:30 ` Olaf van der Spek
  0 siblings, 1 reply; 9+ messages in thread
From: Olaf van der Spek @ 2011-02-28 18:17 UTC (permalink / raw)
  To: binutils

Hi,

I've submitted a feature request for automatic linking via pragma:
http://sourceware.org/bugzilla/show_bug.cgi?id=12485
What do others think about the idea?

-- 
Olaf

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Support for automatic linking via pragma
  2011-02-28 18:17 Support for automatic linking via pragma Olaf van der Spek
@ 2011-03-04 16:30 ` Olaf van der Spek
  2011-03-04 16:44   ` H.J. Lu
  0 siblings, 1 reply; 9+ messages in thread
From: Olaf van der Spek @ 2011-03-04 16:30 UTC (permalink / raw)
  To: binutils

On Mon, Feb 28, 2011 at 7:17 PM, Olaf van der Spek <olafvdspek@gmail.com> wrote:
> Hi,
>
> I've submitted a feature request for automatic linking via pragma:
> http://sourceware.org/bugzilla/show_bug.cgi?id=12485
> What do others think about the idea?

Somebody?

Let me quote the request:
MSVC supports the following pragma, which can be used to automatically link a
library when a header file is included. This is used by for example Boost.

It makes linking with the right lib a lot simpler. No more fiddling
with autoconf to detect the right lib name.

#pragma comment(lib, "requiredLibrary.lib")

Unfortunately, gold doesn't support this. Could you add it?

I assume this needs coordination with gcc.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39437

-- 
Olaf

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Support for automatic linking via pragma
  2011-03-04 16:30 ` Olaf van der Spek
@ 2011-03-04 16:44   ` H.J. Lu
  2011-03-04 16:52     ` Ian Lance Taylor
  2011-03-04 17:31     ` Olaf van der Spek
  0 siblings, 2 replies; 9+ messages in thread
From: H.J. Lu @ 2011-03-04 16:44 UTC (permalink / raw)
  To: Olaf van der Spek; +Cc: binutils

On Fri, Mar 4, 2011 at 8:29 AM, Olaf van der Spek <olafvdspek@gmail.com> wrote:
> On Mon, Feb 28, 2011 at 7:17 PM, Olaf van der Spek <olafvdspek@gmail.com> wrote:
>> Hi,
>>
>> I've submitted a feature request for automatic linking via pragma:
>> http://sourceware.org/bugzilla/show_bug.cgi?id=12485
>> What do others think about the idea?
>
> Somebody?
>
> Let me quote the request:
> MSVC supports the following pragma, which can be used to automatically link a
> library when a header file is included. This is used by for example Boost.
>
> It makes linking with the right lib a lot simpler. No more fiddling
> with autoconf to detect the right lib name.
>

Not necessarily.  Unlike DSO, object files don't have ABI/API
information. You may not link foo.o compiled with glibc 2.5/libbar
1.3 against glibc 2.13/libbar 1.9

-- 
H.J.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Support for automatic linking via pragma
  2011-03-04 16:44   ` H.J. Lu
@ 2011-03-04 16:52     ` Ian Lance Taylor
  2011-03-04 16:55       ` H.J. Lu
  2011-03-04 17:31     ` Olaf van der Spek
  1 sibling, 1 reply; 9+ messages in thread
From: Ian Lance Taylor @ 2011-03-04 16:52 UTC (permalink / raw)
  To: H.J. Lu; +Cc: Olaf van der Spek, binutils

"H.J. Lu" <hjl.tools@gmail.com> writes:

> On Fri, Mar 4, 2011 at 8:29 AM, Olaf van der Spek <olafvdspek@gmail.com> wrote:
>> On Mon, Feb 28, 2011 at 7:17 PM, Olaf van der Spek <olafvdspek@gmail.com> wrote:
>>> Hi,
>>>
>>> I've submitted a feature request for automatic linking via pragma:
>>> http://sourceware.org/bugzilla/show_bug.cgi?id=12485
>>> What do others think about the idea?
>>
>> Somebody?
>>
>> Let me quote the request:
>> MSVC supports the following pragma, which can be used to automatically link a
>> library when a header file is included. This is used by for example Boost.
>>
>> It makes linking with the right lib a lot simpler. No more fiddling
>> with autoconf to detect the right lib name.
>>
>
> Not necessarily.  Unlike DSO, object files don't have ABI/API
> information. You may not link foo.o compiled with glibc 2.5/libbar
> 1.3 against glibc 2.13/libbar 1.9

I don't see how that is relevant to what Olaf is talking about.

What Olaf is saying is that he wants to be able to have a .h file
automatically a -l option to the link command line.

What you are saying is that if that you have a .o file, you have to link
against the -l which corresponds to the .h file which was used when the
.o file was compiled.  That is of course a real problem, but it's a
problem that exists whether or not we implement the MSVC pragma.

Ian

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Support for automatic linking via pragma
  2011-03-04 16:52     ` Ian Lance Taylor
@ 2011-03-04 16:55       ` H.J. Lu
  2011-03-04 17:31         ` Kai Tietz
  2011-03-04 18:40         ` Ian Lance Taylor
  0 siblings, 2 replies; 9+ messages in thread
From: H.J. Lu @ 2011-03-04 16:55 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: Olaf van der Spek, binutils

On Fri, Mar 4, 2011 at 8:52 AM, Ian Lance Taylor <iant@google.com> wrote:
> "H.J. Lu" <hjl.tools@gmail.com> writes:
>
>> On Fri, Mar 4, 2011 at 8:29 AM, Olaf van der Spek <olafvdspek@gmail.com> wrote:
>>> On Mon, Feb 28, 2011 at 7:17 PM, Olaf van der Spek <olafvdspek@gmail.com> wrote:
>>>> Hi,
>>>>
>>>> I've submitted a feature request for automatic linking via pragma:
>>>> http://sourceware.org/bugzilla/show_bug.cgi?id=12485
>>>> What do others think about the idea?
>>>
>>> Somebody?
>>>
>>> Let me quote the request:
>>> MSVC supports the following pragma, which can be used to automatically link a
>>> library when a header file is included. This is used by for example Boost.
>>>
>>> It makes linking with the right lib a lot simpler. No more fiddling
>>> with autoconf to detect the right lib name.
>>>
>>
>> Not necessarily.  Unlike DSO, object files don't have ABI/API
>> information. You may not link foo.o compiled with glibc 2.5/libbar
>> 1.3 against glibc 2.13/libbar 1.9
>
> I don't see how that is relevant to what Olaf is talking about.
>
> What Olaf is saying is that he wants to be able to have a .h file
> automatically a -l option to the link command line.

Don't you need to store such information in object files?

> What you are saying is that if that you have a .o file, you have to link
> against the -l which corresponds to the .h file which was used when the
> .o file was compiled.  That is of course a real problem, but it's a
> problem that exists whether or not we implement the MSVC pragma.
>

There is no such problem for DSO since we can encode ABI/API
info in DSO.

-- 
H.J.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Support for automatic linking via pragma
  2011-03-04 16:44   ` H.J. Lu
  2011-03-04 16:52     ` Ian Lance Taylor
@ 2011-03-04 17:31     ` Olaf van der Spek
  1 sibling, 0 replies; 9+ messages in thread
From: Olaf van der Spek @ 2011-03-04 17:31 UTC (permalink / raw)
  To: H.J. Lu; +Cc: binutils

On Fri, Mar 4, 2011 at 5:44 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
> Not necessarily.  Unlike DSO, object files don't have ABI/API
> information. You may not link foo.o compiled with glibc 2.5/libbar
> 1.3 against glibc 2.13/libbar 1.9

It's (at first) intended for apps that just use:
-lboost_program_options-mt
-lboost_system-mt
-lctemplate
-lmysqlclient
-lpthread
-lxbt
-lz
With this feature, they don't need to pass this info automatically.

> You may not link foo.o compiled with glibc 2.5/libbar
> 1.3 against glibc 2.13/libbar 1.9

True, but that's a different problem. One that might benefit from auto linking.

Is the ABI/API info encoded in the lib name?
-- 
Olaf

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Support for automatic linking via pragma
  2011-03-04 16:55       ` H.J. Lu
@ 2011-03-04 17:31         ` Kai Tietz
  2011-03-04 17:35           ` Olaf van der Spek
  2011-03-04 18:40         ` Ian Lance Taylor
  1 sibling, 1 reply; 9+ messages in thread
From: Kai Tietz @ 2011-03-04 17:31 UTC (permalink / raw)
  To: H.J. Lu; +Cc: Ian Lance Taylor, Olaf van der Spek, binutils

2011/3/4 H.J. Lu <hjl.tools@gmail.com>:
> On Fri, Mar 4, 2011 at 8:52 AM, Ian Lance Taylor <iant@google.com> wrote:
>> "H.J. Lu" <hjl.tools@gmail.com> writes:
>>
>>> On Fri, Mar 4, 2011 at 8:29 AM, Olaf van der Spek <olafvdspek@gmail.com> wrote:
>>>> On Mon, Feb 28, 2011 at 7:17 PM, Olaf van der Spek <olafvdspek@gmail.com> wrote:
>>>>> Hi,
>>>>>
>>>>> I've submitted a feature request for automatic linking via pragma:
>>>>> http://sourceware.org/bugzilla/show_bug.cgi?id=12485
>>>>> What do others think about the idea?
>>>>
>>>> Somebody?
>>>>
>>>> Let me quote the request:
>>>> MSVC supports the following pragma, which can be used to automatically link a
>>>> library when a header file is included. This is used by for example Boost.
>>>>
>>>> It makes linking with the right lib a lot simpler. No more fiddling
>>>> with autoconf to detect the right lib name.
>>>>
>>>
>>> Not necessarily.  Unlike DSO, object files don't have ABI/API
>>> information. You may not link foo.o compiled with glibc 2.5/libbar
>>> 1.3 against glibc 2.13/libbar 1.9
>>
>> I don't see how that is relevant to what Olaf is talking about.
>>
>> What Olaf is saying is that he wants to be able to have a .h file
>> automatically a -l option to the link command line.
>
> Don't you need to store such information in object files?
>
>> What you are saying is that if that you have a .o file, you have to link
>> against the -l which corresponds to the .h file which was used when the
>> .o file was compiled.  That is of course a real problem, but it's a
>> problem that exists whether or not we implement the MSVC pragma.
>>
>
> There is no such problem for DSO since we can encode ABI/API
> info in DSO.
>
> --
> H.J.
>

Hello,

my 1 cent for this feature. I did some research for this feature a
while ago. Actual it is still on my todo-list for some time, but the
details of it scared me to do it actually. The additional
link-information is (for PE-COFF) in directive-section (like
additional aliasing, export-information, entry, and co). For ELF the
.comment section should be the equivalent, isn't it?

I didn't found time to work on that in more detail for PE-COFF and
indeed is for it the dependency-tree for objects/libraries the
challenging part.
As for doing this on each used object base, means we have on link-time
a changing import dependency tree, as each object actual used could
generate new one. This easily can lead to cycles and is IMHO too
costy.
So my research had shown that it would be more efficent (and not that
complex), to pre-scan those directives before the actual link-phase
and build up the object/library link dependency-tree once.
The gcc pragma implementation would be straight-forward and obvious.

Kai

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Support for automatic linking via pragma
  2011-03-04 17:31         ` Kai Tietz
@ 2011-03-04 17:35           ` Olaf van der Spek
  0 siblings, 0 replies; 9+ messages in thread
From: Olaf van der Spek @ 2011-03-04 17:35 UTC (permalink / raw)
  To: Kai Tietz; +Cc: binutils

On Fri, Mar 4, 2011 at 6:31 PM, Kai Tietz <ktietz70@googlemail.com> wrote:
> I didn't found time to work on that in more detail for PE-COFF and
> indeed is for it the dependency-tree for objects/libraries the
> challenging part.
> As for doing this on each used object base, means we have on link-time
> a changing import dependency tree, as each object actual used could
> generate new one. This easily can lead to cycles and is IMHO too
> costy.
> So my research had shown that it would be more efficent (and not that
> complex), to pre-scan those directives before the actual link-phase
> and build up the object/library link dependency-tree once.
> The gcc pragma implementation would be straight-forward and obvious.

I didn't consider this issue yet. I remember in the distant past I had
some issues with lib ordering, but in the recent past I didn't. Did
GCC avoid this issue or was I just lucky?
If it did avoid it, I assume that code can be reused.

-- 
Olaf

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Support for automatic linking via pragma
  2011-03-04 16:55       ` H.J. Lu
  2011-03-04 17:31         ` Kai Tietz
@ 2011-03-04 18:40         ` Ian Lance Taylor
  1 sibling, 0 replies; 9+ messages in thread
From: Ian Lance Taylor @ 2011-03-04 18:40 UTC (permalink / raw)
  To: H.J. Lu; +Cc: Olaf van der Spek, binutils

"H.J. Lu" <hjl.tools@gmail.com> writes:

> On Fri, Mar 4, 2011 at 8:52 AM, Ian Lance Taylor <iant@google.com> wrote:
>> "H.J. Lu" <hjl.tools@gmail.com> writes:
>>
>>> On Fri, Mar 4, 2011 at 8:29 AM, Olaf van der Spek <olafvdspek@gmail.com> wrote:
>>>> MSVC supports the following pragma, which can be used to automatically link a
>>>> library when a header file is included. This is used by for example Boost.
>>>>
>>>> It makes linking with the right lib a lot simpler. No more fiddling
>>>> with autoconf to detect the right lib name.
>>>>
>>>
>>> Not necessarily.  Unlike DSO, object files don't have ABI/API
>>> information. You may not link foo.o compiled with glibc 2.5/libbar
>>> 1.3 against glibc 2.13/libbar 1.9
>>
>> I don't see how that is relevant to what Olaf is talking about.
>>
>> What Olaf is saying is that he wants to be able to have a .h file
>> automatically a -l option to the link command line.
>
> Don't you need to store such information in object files?

Yes, but so what?  The meaning of the information in the object file is
"when linking, add this -l option".  That is not different from what
exists today, except that today you have to remember to add the -l
option yourself.  Today, if you have an old object file, and you add the
-l option yourself on the link line, you will have trouble.  This
proposal does not change that.  It addresses a different issue.

In the hopes of being more clear, the issue that this proposal addresses
is that if your code does a #include <glib.h>, you have to also add
-lglib on your command line.  If this proposal were implemented, the
second step would be unnecessary.  This makes writing Makefiles simpler.


>> What you are saying is that if that you have a .o file, you have to link
>> against the -l which corresponds to the .h file which was used when the
>> .o file was compiled.  That is of course a real problem, but it's a
>> problem that exists whether or not we implement the MSVC pragma.
>>
>
> There is no such problem for DSO since we can encode ABI/API
> info in DSO.

Yes, of course, but irrelevant to the issue at hand.

Ian

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2011-03-04 18:40 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-02-28 18:17 Support for automatic linking via pragma Olaf van der Spek
2011-03-04 16:30 ` Olaf van der Spek
2011-03-04 16:44   ` H.J. Lu
2011-03-04 16:52     ` Ian Lance Taylor
2011-03-04 16:55       ` H.J. Lu
2011-03-04 17:31         ` Kai Tietz
2011-03-04 17:35           ` Olaf van der Spek
2011-03-04 18:40         ` Ian Lance Taylor
2011-03-04 17:31     ` Olaf van der Spek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).