threads / patch / 4828

patchFix linking for not-so-clever linkers.

Subject: [PATCH] Fix linking for not-so-clever linkers.

## tl;dr

5 messages between Jul 10, 2006 and Jul 10, 2006. Diffs are folded; open one to read it.

replies: 4people: 3as markdown or json

Johannes Schindelin· Jul 10, 2006, 11:40 UTC · lore

On one of my systems, the linker is not intelligent enough to link with pager.o (in libgit.a) when only the variable pager_in_use is needed. The consequence is that the linker complains about an undefined variable. So, put the variable into environment.o, where it is linked always.

Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
---
 environment.c |    1 +
 pager.c       |    2 --
 2 files changed, 1 insertions(+), 2 deletions(-)
Show changes to 2 files +1 −2

environment.c, pager.c

diff --git a/environment.c b/environment.c
index 43823ff..97d42b1 100644
--- a/environment.c
+++ b/environment.c
@@ -21,6 +21,7 @@ char git_commit_encoding[MAX_ENCODING_LE
 int shared_repository = PERM_UMASK;
 const char *apply_default_whitespace = NULL;
 int zlib_compression_level = Z_DEFAULT_COMPRESSION;
+int pager_in_use;
 
 static char *git_dir, *git_object_dir, *git_index_file, *git_refs_dir,
 	*git_graft_file;
diff --git a/pager.c b/pager.c
index bb14e99..280f57f 100644
--- a/pager.c
+++ b/pager.c
@@ -5,8 +5,6 @@ #include "cache.h"
  * something different on Windows, for example.
  */
 
-int pager_in_use;
-
 static void run_pager(const char *pager)
 {
 	execlp(pager, pager, NULL);
-- 
1.4.1.g6e33b-dirty
Junio C Hamano· Jul 10, 2006, 21:25 UTC · re: Johannes Schindelin · lore

Re: [PATCH] Fix linking for not-so-clever linkers.

Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
> On one of my systems, the linker is not intelligent enough to link with
> pager.o (in libgit.a) when only the variable pager_in_use is needed. The
> consequence is that the linker complains about an undefined
> variable.

I do not understand this quite yet -- which executable is your linker building when it does this?

Maybe we need ranlib?
Linus Torvalds· Jul 10, 2006, 21:34 UTC · re: Junio C Hamano · lore

Re: [PATCH] Fix linking for not-so-clever linkers.

On Mon, 10 Jul 2006, Junio C Hamano wrote:
Show 12 quoted lines
>
> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
> 
> > On one of my systems, the linker is not intelligent enough to link with
> > pager.o (in libgit.a) when only the variable pager_in_use is needed. The
> > consequence is that the linker complains about an undefined
> > variable.
> 
> I do not understand this quite yet -- which executable is your
> linker building when it does this?
> 
> Maybe we need ranlib?

Shouldn't be needed, since we use "$(AR) rcs", where that "s" should do the equivalent of the old-fashioned "ranlib" call.

However, that said, I think Johannes' patch is worth applying regardless, since it's kind of sad to link in pager.o just because of a variable that ends up never mattering (ie any program that uses "diff.c" but isn't built-in).

Of course, once/if everything is built-in, this doesn't matter, but in the meantime this isn't the first time we've re-organized things so that you don't have to link in files that you don't need. After all, that was the whole reason environment.c ended up existing in the first place..

			Linus
Junio C Hamano· Jul 10, 2006, 21:48 UTC · re: Linus Torvalds · lore

Re: [PATCH] Fix linking for not-so-clever linkers.

Linus Torvalds <torvalds@osdl.org> writes:
Show 11 quoted lines
> On Mon, 10 Jul 2006, Junio C Hamano wrote:
>>
>> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
>> 
>> > On one of my systems, the linker is not intelligent enough to link with
>> > pager.o (in libgit.a) when only the variable pager_in_use is needed. The
>> > consequence is that the linker complains about an undefined
>> > variable.
>> 
>> I do not understand this quite yet -- which executable is your
>> linker building when it does this?
Show 5 quoted lines
>> Maybe we need ranlib?
>
> Shouldn't be needed, since we use "$(AR) rcs",...
> ... After all, that was the 
> whole reason environment.c ended up existing in the first place..
Understood and agreed to everything you said.

But I still wonder why/how it happens in Johannes's environment...

Johannes Schindelin· Jul 10, 2006, 23:01 UTC · re: Junio C Hamano · lore

Re: [PATCH] Fix linking for not-so-clever linkers.

Hi,
On Mon, 10 Jul 2006, Junio C Hamano wrote:
Show 9 quoted lines
> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
> 
> > On one of my systems, the linker is not intelligent enough to link with
> > pager.o (in libgit.a) when only the variable pager_in_use is needed. The
> > consequence is that the linker complains about an undefined
> > variable.
> 
> I do not understand this quite yet -- which executable is your
> linker building when it does this?

The problem arises for the first time with git-blame. (Have not checked which other executables might be affected.)

> Maybe we need ranlib?

Does not help. pager.o is in libgit.a. Still, Darwin's linker does not want to link to pager.o (probably because no function from pager.o is called, so this is a real bug in the Darwin linker -- but being easy to fix, I think it is worthwhile to fix it).

Ciao, Dscho

← back to recent threads