threads / discuss / 50648

Can't build first git commit

Subject: Can't build first git commit

## tl;dr

18 messages between Mar 4, 2019 and Mar 7, 2019.

replies: 17people: 5as markdown or json

Fabio Aiuto· Mar 4, 2019, 19:58 UTC · lore
Hi to all,

I'm trying to build first commit of git made by Linus. I mean the one named e83c5163316f89bfbde7d9ab23... (I think this is enough). But at building stage i have the following error:

make all  gcc -g -o update-cache update-cache.o read-cache.o -lssl /usr/bin/ld: update-cache.o: undefined reference to symbol 'SHA1_Update@@OPENSSL_1_1_0' //usr/lib/i386-linux-gnu/libcrypto.so.1.1: error adding symbols: DSO missing from command line collect2: error: ld returned 1 exit status make: *** [update-cache] Errore 1 Makefile:16: set di istruzioni per l'obiettivo "update-cache" non riuscito

I run a debian stretch on my machine. Could anyone help me? Thanks in advance. Fabio.

Santiago Torres· Mar 4, 2019, 20:10 UTC · re: Fabio Aiuto · lore

Re: Can't build first git commit

This commit is about 14 years old:
    Date:   Thu Apr 7 15:13:13 2005 -0700

Unless you have a toolchain from around that time, I'd be very surprised if things build. Notably, there you're having an issue with the symbols that lssl is exposing (I suspect you're not even using the openssl 1.0.0 series anymore.

Thanks, -Santiago.

On Mon, Mar 04, 2019 at 08:58:37PM +0100, Fabio Aiuto wrote:
Show 21 quoted lines
> Hi to all,
> 
> I'm trying to build first commit of git made by Linus. I mean the one
> named e83c5163316f89bfbde7d9ab23... (I think this is enough).
> But at building stage i have the following error:
> 
> make all 
> gcc -g -o update-cache update-cache.o read-cache.o -lssl
> /usr/bin/ld: update-cache.o: undefined reference to symbol
> 'SHA1_Update@@OPENSSL_1_1_0'
> //usr/lib/i386-linux-gnu/libcrypto.so.1.1: error adding symbols: DSO
> missing from command line
> collect2: error: ld returned 1 exit status
> make: *** [update-cache] Errore 1
> Makefile:16: set di istruzioni per l'obiettivo "update-cache" non
> riuscito
> 
> I run a debian stretch on my machine. Could anyone help me?
> Thanks in advance.
> Fabio.
> 
Fabio Aiuto· Mar 4, 2019, 20:19 UTC · re: Santiago Torres · lore

Re: Can't build first git commit

What a pity, It would have been very useful for me, to debug around that simple version, to understand how everithing works. Thank you Santiago. Fabio. Il giorno lun, 04/03/2019 alle 15.10 -0500, Santiago Torres ha scritto:

Show 39 quoted lines
> This commit is about 14 years old:
> 
>     Date:   Thu Apr 7 15:13:13 2005 -0700
> 
> Unless you have a toolchain from around that time, I'd be very
> surprised
> if things build. Notably, there you're having an issue with the
> symbols
> that lssl is exposing (I suspect you're not even using the openssl
> 1.0.0
> series anymore.
> 
> Thanks,
> -Santiago.
> 
> On Mon, Mar 04, 2019 at 08:58:37PM +0100, Fabio Aiuto wrote:
> > Hi to all,
> > 
> > I'm trying to build first commit of git made by Linus. I mean the
> > one
> > named e83c5163316f89bfbde7d9ab23... (I think this is enough).
> > But at building stage i have the following error:
> > 
> > make all 
> > gcc -g -o update-cache update-cache.o read-cache.o -lssl
> > /usr/bin/ld: update-cache.o: undefined reference to symbol
> > 'SHA1_Update@@OPENSSL_1_1_0'
> > //usr/lib/i386-linux-gnu/libcrypto.so.1.1: error adding symbols:
> > DSO
> > missing from command line
> > collect2: error: ld returned 1 exit status
> > make: *** [update-cache] Errore 1
> > Makefile:16: set di istruzioni per l'obiettivo "update-cache" non
> > riuscito
> > 
> > I run a debian stretch on my machine. Could anyone help me?
> > Thanks in advance.
> > Fabio.
> > 
Santiago Torres· Mar 4, 2019, 20:22 UTC · re: Fabio Aiuto · lore

Re: Can't build first git commit

It happens. 

Something that I liked playing with to get myself a better handle of how git works is using libgit2 and its python bindings. I find the codebase a little bit smaller and its bindings to higher-level languages can help you abstract the memory management and other low-level stuff that is sometimes distracting.

Good luck! -Santiago.

On Mon, Mar 04, 2019 at 09:19:52PM +0100, Fabio Aiuto wrote:
Show 44 quoted lines
> What a pity, It would have been very useful for me, to debug around
> that simple version, to understand how everithing works.
> Thank you Santiago.
> Fabio.
> Il giorno lun, 04/03/2019 alle 15.10 -0500, Santiago Torres ha scritto:
> > This commit is about 14 years old:
> > 
> >     Date:   Thu Apr 7 15:13:13 2005 -0700
> > 
> > Unless you have a toolchain from around that time, I'd be very
> > surprised
> > if things build. Notably, there you're having an issue with the
> > symbols
> > that lssl is exposing (I suspect you're not even using the openssl
> > 1.0.0
> > series anymore.
> > 
> > Thanks,
> > -Santiago.
> > 
> > On Mon, Mar 04, 2019 at 08:58:37PM +0100, Fabio Aiuto wrote:
> > > Hi to all,
> > > 
> > > I'm trying to build first commit of git made by Linus. I mean the
> > > one
> > > named e83c5163316f89bfbde7d9ab23... (I think this is enough).
> > > But at building stage i have the following error:
> > > 
> > > make all 
> > > gcc -g -o update-cache update-cache.o read-cache.o -lssl
> > > /usr/bin/ld: update-cache.o: undefined reference to symbol
> > > 'SHA1_Update@@OPENSSL_1_1_0'
> > > //usr/lib/i386-linux-gnu/libcrypto.so.1.1: error adding symbols:
> > > DSO
> > > missing from command line
> > > collect2: error: ld returned 1 exit status
> > > make: *** [update-cache] Errore 1
> > > Makefile:16: set di istruzioni per l'obiettivo "update-cache" non
> > > riuscito
> > > 
> > > I run a debian stretch on my machine. Could anyone help me?
> > > Thanks in advance.
> > > Fabio.
> > > 
asymptosis· Mar 4, 2019, 21:48 UTC · re: Fabio Aiuto · lore

Re: Can't build first git commit

On Mon, Mar 04, 2019 at 09:19:52PM +0100, Fabio Aiuto wrote:
> What a pity, It would have been very useful for me, to debug around
> that simple version, to understand how everithing works.

To understand how Git works, it is a good idea to work through the "Git Internals" chapter in the Git Book:

https://git-scm.com/book/en/v2/Git-Internals-Plumbing-and-Porcelain

To help me understand that chapter, I started re-implementing Git as simple bash scripts, which have been placed at https://notabug.org/cryptarch/sgit

Jonathan Nieder· Mar 4, 2019, 22:25 UTC · re: Fabio Aiuto · lore

Re: Can't build first git commit

Hi,
Fabio Aiuto wrote:
> What a pity, It would have been very useful for me, to debug around
> that simple version, to understand how everithing works.

Jeff King suggested how you can update the build command to get it working. In general, I think people sometimes overthink what is involved in a build: something like

	cc *.c

plus appropriate warning, optimization, debug, -D, and library flags should work just fine.

If you haven't already read it, I also recommend reading https://www.kernel.org/pub/software/scm/git/docs/user-manual.html#hacking-git. If you have ideas for improving the text there (perhaps with suggested build instructions?), patches to Documentation/user-manual.txt are very welcome.

Thanks and happy hacking, Jonathan

Jeff King· Mar 4, 2019, 20:40 UTC · re: Fabio Aiuto · lore

Re: Can't build first git commit

On Mon, Mar 04, 2019 at 08:58:37PM +0100, Fabio Aiuto wrote:
Show 8 quoted lines
> I'm trying to build first commit of git made by Linus. I mean the one
> named e83c5163316f89bfbde7d9ab23... (I think this is enough).
> But at building stage i have the following error:
> 
> make all 
> gcc -g -o update-cache update-cache.o read-cache.o -lssl
> /usr/bin/ld: update-cache.o: undefined reference to symbol
> 'SHA1_Update@@OPENSSL_1_1_0'

The sha1 routines are in libcrypto. See 3be4b61aa4 (Link with -lcrypto instead of -lssl when using openssl libraries., 2005-05-10). I also needed -lz. See 9426167765 (Add "-lz" to link line to get in zlib., 2005-04-08).

You can patch the Makefile, or just override it like:
  make LIBS='-lcrypto -lz'

which builds for me on current Debian unstable. I don't think you can actually fetch with that old build, but I used periodically check that Git v1.0 can fetch happily from GitHub. I haven't in a while, so let me know if you try it and it doesn't work. ;)

-Peff
Fabio Aiuto· Mar 5, 2019, 18:42 UTC · re: Jeff King · lore

Re: Can't build first git commit

Thank you Jeff I'll have news within few days!!! Il giorno lun, 04/03/2019 alle 15.40 -0500, Jeff King ha scritto:

Show 30 quoted lines
> On Mon, Mar 04, 2019 at 08:58:37PM +0100, Fabio Aiuto wrote:
> 
> > I'm trying to build first commit of git made by Linus. I mean the
> > one
> > named e83c5163316f89bfbde7d9ab23... (I think this is enough).
> > But at building stage i have the following error:
> > 
> > make all 
> > gcc -g -o update-cache update-cache.o read-cache.o -lssl
> > /usr/bin/ld: update-cache.o: undefined reference to symbol
> > 'SHA1_Update@@OPENSSL_1_1_0'
> 
> The sha1 routines are in libcrypto. See 3be4b61aa4 (Link with
> -lcrypto
> instead of -lssl when using openssl libraries., 2005-05-10). I also
> needed -lz. See 9426167765 (Add "-lz" to link line to get in zlib.,
> 2005-04-08).
> 
> You can patch the Makefile, or just override it like:
> 
>   make LIBS='-lcrypto -lz'
> 
> which builds for me on current Debian unstable. I don't think you can
> actually fetch with that old build, but I used periodically check
> that
> Git v1.0 can fetch happily from GitHub. I haven't in a while, so let
> me
> know if you try it and it doesn't work. ;)
> 
> -Peff
Jeff King· Mar 5, 2019, 19:15 UTC · re: Jeff King · lore

Re: Can't build first git commit

On Mon, Mar 04, 2019 at 03:40:07PM -0500, Jeff King wrote:
Show 8 quoted lines
> You can patch the Makefile, or just override it like:
> 
>   make LIBS='-lcrypto -lz'
> 
> which builds for me on current Debian unstable. I don't think you can
> actually fetch with that old build, but I used periodically check that
> Git v1.0 can fetch happily from GitHub. I haven't in a while, so let me
> know if you try it and it doesn't work. ;)
I just tried this, and it does indeed work. I had to build v1.0.0 with
  make NO_OPENSSL=Nope

I think the issue is that some old code embedded openssl's BIGNUM in a struct, and later versions of openssl stopped publicly defining the types.

I was able to clone git://github.com/git/git with the result, though of course it chokes no the sha1collisiondetection submodule. You can still use "git log", though, and checkout older commits.

-Peff
Fabio Aiuto· Mar 6, 2019, 19:58 UTC · re: Jeff King · lore

Re: Can't build first git commit

Il giorno mar, 05/03/2019 alle 14.15 -0500, Jeff King ha scritto:
Show 31 quoted lines
> On Mon, Mar 04, 2019 at 03:40:07PM -0500, Jeff King wrote:
> 
> > You can patch the Makefile, or just override it like:
> > 
> >   make LIBS='-lcrypto -lz'
> > 
> > which builds for me on current Debian unstable. I don't think you
> > can
> > actually fetch with that old build, but I used periodically check
> > that
> > Git v1.0 can fetch happily from GitHub. I haven't in a while, so
> > let me
> > know if you try it and it doesn't work. ;)
> 
> I just tried this, and it does indeed work. I had to build v1.0.0
> with
> 
>   make NO_OPENSSL=Nope
> 
> I think the issue is that some old code embedded openssl's BIGNUM in
> a
> struct, and later versions of openssl stopped publicly defining the
> types.
> 
> I was able to clone git://github.com/git/git with the result, though
> of
> course it chokes no the sha1collisiondetection submodule. You can
> still
> use "git log", though, and checkout older commits.
> 
> -Peff
Hi Jeff,
I've just typed make make LIBS='-lcrypto -lz' from the shell inside the
 
directory containing the whole first commit and it seems to work. I
trace all through the code. Yes the fetch command wasn't written at
that time, right? I didn't understand why should be better to work with
the git code from github. There's something I misunderstood?
Thank you Jeff ;-)
Jeff King· Mar 6, 2019, 20:03 UTC · re: Fabio Aiuto · lore

Re: Can't build first git commit

On Wed, Mar 06, 2019 at 08:58:40PM +0100, Fabio Aiuto wrote:
> Yes the fetch command wasn't written at that time, right? I didn't
> understand why should be better to work with the git code from github.
> There's something I misunderstood?

I just mean that it is an interesting fact that modern Git and Git v1.0 can still interact seamlessly over the network. I.e., you could still collaborate with somebody using an ancient version of Git (hopefully nobody is using v1.0, but logically it extends to all of the intermediate versions).

-Peff
Fabio Aiuto· Mar 6, 2019, 20:19 UTC · re: Jeff King · lore

Re: Can't build first git commit

Yes that's great. Why somebody told me about a outdate toolchain when I started this little thread about first git compiling? Sorry for my stupid question but the you just resolved with that make override... Maybe there's something I have to know?

Il giorno mer, 06/03/2019 alle 15.03 -0500, Jeff King ha scritto:
Show 15 quoted lines
> On Wed, Mar 06, 2019 at 08:58:40PM +0100, Fabio Aiuto wrote:
> 
> > Yes the fetch command wasn't written at that time, right? I didn't
> > understand why should be better to work with the git code from
> > github.
> > There's something I misunderstood?
> 
> I just mean that it is an interesting fact that modern Git and Git
> v1.0
> can still interact seamlessly over the network. I.e., you could still
> collaborate with somebody using an ancient version of Git (hopefully
> nobody is using v1.0, but logically it extends to all of the
> intermediate versions).
> 
> -Peff
Santiago Torres· Mar 6, 2019, 20:39 UTC · re: Fabio Aiuto · lore

Re: Can't build first git commit

That was proably my bad. 

I still find it somewhat astounding that it compiles with a modern toolchain after 15+ years. Many projects fail to do so (it's an understandably high bar to have).

I'm glad this is possible and you were able to do so (maybe you want to share your experiences about it somewhere? :))

Cheers! -Santiago.

On Wed, Mar 06, 2019 at 09:19:58PM +0100, Fabio Aiuto wrote:
Show 22 quoted lines
> Yes that's great.
> Why somebody told me about a outdate toolchain when I started this
> little thread about first git compiling? Sorry for my stupid question
> but the you just resolved with that make override...
> Maybe there's something I have to know?
> 
> Il giorno mer, 06/03/2019 alle 15.03 -0500, Jeff King ha scritto:
> > On Wed, Mar 06, 2019 at 08:58:40PM +0100, Fabio Aiuto wrote:
> > 
> > > Yes the fetch command wasn't written at that time, right? I didn't
> > > understand why should be better to work with the git code from
> > > github.
> > > There's something I misunderstood?
> > 
> > I just mean that it is an interesting fact that modern Git and Git
> > v1.0
> > can still interact seamlessly over the network. I.e., you could still
> > collaborate with somebody using an ancient version of Git (hopefully
> > nobody is using v1.0, but logically it extends to all of the
> > intermediate versions).
> > 
> > -Peff
Jeff King· Mar 6, 2019, 21:54 UTC · re: Santiago Torres · lore

Re: Can't build first git commit

On Wed, Mar 06, 2019 at 03:39:11PM -0500, Santiago Torres wrote:
> I still find it somewhat astounding that it compiles with a modern
> toolchain after 15+ years. Many projects fail to do so (it's an
> understandably high bar to have).

I think the key thing is that Git has very few external dependencies. You'll note that I had to turn off OpenSSL support to get it to compile. The only other library from back then is libz, which is extremely stable.

Other than, it just depends on a reasonable C compiler and a POSIX libc, both of which have been standardized for decades.

I suspect that today's Git will also compile pretty well in 15 years, but you'll probably to say NO_GETTEXT and turn a few other knobs. Libcurl might eventually be a problem, though I've been pretty impressed with its stability and backwards-compatibility so far (and of course it's optional if disabling http support is OK).

-Peff
Fabio Aiuto· Mar 6, 2019, 20:52 UTC · re: Jeff King · lore

Re: Can't build first git commit

Found this error

Program received signal SIGSEGV, Segmentation fault. 0x00401628 in verify_hdr (hdr=0x0, size=32) at read-cache.c:192 192 if (hdr->signature != CACHE_SIGNATURE)

when tracing on line
static int verify_hdr(struct cache_header *hdr, unsigned long size)
{
	SHA_CTX c;
	unsigned char sha1[20];
	if (hdr->signature != CACHE_SIGNATURE)<--- this line

inside file read-cache.c What's going on?

Il giorno mer, 06/03/2019 alle 15.03 -0500, Jeff King ha scritto:
Show 15 quoted lines
> On Wed, Mar 06, 2019 at 08:58:40PM +0100, Fabio Aiuto wrote:
> 
> > Yes the fetch command wasn't written at that time, right? I didn't
> > understand why should be better to work with the git code from
> > github.
> > There's something I misunderstood?
> 
> I just mean that it is an interesting fact that modern Git and Git
> v1.0
> can still interact seamlessly over the network. I.e., you could still
> collaborate with somebody using an ancient version of Git (hopefully
> nobody is using v1.0, but logically it extends to all of the
> intermediate versions).
> 
> -Peff
Jeff King· Mar 6, 2019, 21:57 UTC · re: Fabio Aiuto · lore

Re: Can't build first git commit

On Wed, Mar 06, 2019 at 09:52:59PM +0100, Fabio Aiuto wrote:
Show 17 quoted lines
> Found this error
> 
> Program received signal SIGSEGV, Segmentation fault.
> 0x00401628 in verify_hdr (hdr=0x0, size=32) at read-cache.c:192
> 192		if (hdr->signature != CACHE_SIGNATURE)
> 
> when tracing on line
> 
> static int verify_hdr(struct cache_header *hdr, unsigned long size)
> {
> 	SHA_CTX c;
> 	unsigned char sha1[20];
> 
> 	if (hdr->signature != CACHE_SIGNATURE)<--- this line
> 
> inside file read-cache.c
> What's going on?

Well, hdr is NULL, so you can't dereference it. Without knowing more about how you called it, it's hard to say. But do note that the index format has been updated once or twice (as well as the pack format). You probably can't just chdir into a clone made by a recent Git and expect ancient versions to read it.

You'll have to start a repo from scratch, or clone an existing with the old version (which will be tricky; you might have to use a modern upload-pack to represent the server side, but I think that first version doesn't even have any fetch capabilities at all).

It might also be possible to convince modern Git to write out in old formats that ancient Git will understand, but I don't know the right config knobs to tweak offhand.

-Peff
Jeff King· Mar 7, 2019, 19:41 UTC · lore

Re: Can't build first git commit

[+cc git@vger; let's keep this on the list; I'm not sure there's a lot
 to be learned from fiddling with this old version, but if we're going
 to do it, let's at least record our attempts for posterity]
On Thu, Mar 07, 2019 at 08:04:55PM +0100, Fabio Aiuto wrote:
Show 11 quoted lines
> I made a directory "trial" and inside it I ran init-db (that's the
> grand-father of git init) inside that directory. Then I created a file 
> this way:
> 
> echo 'helloooo!' >file.txt
> 
> then then executed update-cache file.txt (thinking that's the ancestor
> of git add), but that doesn't work and it returns with a segmentation
> fault, due to the nullity of the header. But in this first commit how
> do I add a file in the cache? What's the right way to build up a
> repository from scratch with commit e83c5163316f?

Hmm. I tried that, too, and got a segfault. Then I tried it again a few minutes later, and it worked.

One thing that seems to provoke it consistently is having a zero-length index file (because that causes mmap to return NULL, and the code does not check for that case). Try this:

  # This works.
  init-db
  echo content >file
  update-cache file
  # This segfaults
  >.dircache/index
  update-cache file
  # And this works again
  rm .dircache/index
  update-cache file

I'm not sure why it would ever fail without that explicit empty-file write. Perhaps there's some code path that writes out an empty index file, and we inadvertently triggered it.

If you're going to play with such an antique commit, you have to expect that things won't necessarily work, and be ready to poke around in the debugger.

-Peff
Fabio Aiuto· Mar 7, 2019, 20:07 UTC · re: Jeff King · lore

Re: Can't build first git commit

Sorry for forgetting the cc!!! Thank you so much for help, hope not to bore you all ;) I think that I will go on studying git this way, and follow all the improvements that were made along his history. I think that asymptosis too gave me a good link, related to that bash script implmentation. Thank you Jeff, now I'm trying to understand how could I show the contents of the index in that version.

Fabio.
Il giorno gio, 07/03/2019 alle 14.41 -0500, Jeff King ha scritto:
Show 58 quoted lines
> [+cc git@vger; let's keep this on the list; I'm not sure there's a
> lot
>  to be learned from fiddling with this old version, but if we're
> going
>  to do it, let's at least record our attempts for posterity]
> 
> On Thu, Mar 07, 2019 at 08:04:55PM +0100, Fabio Aiuto wrote:
> 
> > I made a directory "trial" and inside it I ran init-db (that's the
> > grand-father of git init) inside that directory. Then I created a
> > file 
> > this way:
> > 
> > echo 'helloooo!' >file.txt
> > 
> > then then executed update-cache file.txt (thinking that's the
> > ancestor
> > of git add), but that doesn't work and it returns with a
> > segmentation
> > fault, due to the nullity of the header. But in this first commit
> > how
> > do I add a file in the cache? What's the right way to build up a
> > repository from scratch with commit e83c5163316f?
> 
> Hmm. I tried that, too, and got a segfault. Then I tried it again a
> few
> minutes later, and it worked.
> 
> One thing that seems to provoke it consistently is having a zero-
> length
> index file (because that causes mmap to return NULL, and the code
> does
> not check for that case). Try this:
> 
>   # This works.
>   init-db
>   echo content >file
>   update-cache file
> 
>   # This segfaults
>   >.dircache/index
>   update-cache file
> 
>   # And this works again
>   rm .dircache/index
>   update-cache file
> 
> I'm not sure why it would ever fail without that explicit empty-file
> write. Perhaps there's some code path that writes out an empty index
> file, and we inadvertently triggered it.
> 
> If you're going to play with such an antique commit, you have to
> expect
> that things won't necessarily work, and be ready to poke around in
> the
> debugger.
> 
> -Peff

← back to recent threads