Skip to contentSkip to conversation

Can't build first git commit

DISCUSSION Fabio Aiuto 5 participants 18 messages Mar 4, 2019 – Mar 7, 2019 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

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.

#1 lore raw

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.

Quoted 21 lines · Fabio Aiuto

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.

#2 lore raw

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:

Quoted 39 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.

Quoted 23 lines · Fabio Aiuto

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.

#3 lore raw

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.

Quoted 44 lines · Fabio Aiuto

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:

Quoted 39 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.

Quoted 23 lines · Fabio Aiuto

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.

#6 lore raw
In reply to Fabio Aiuto
Quoted 8 lines · Fabio Aiuto

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

#4 lore raw
In reply to Fabio Aiuto
Quoted 2 lines · Fabio Aiuto

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

#5 lore raw
In reply to Fabio Aiuto

Hi,

Quoted 2 lines · Fabio Aiuto

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

#7 lore raw
In reply to Jeff King

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

Quoted 30 lines · Fabio Aiuto
Quoted 10 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

#8 lore raw
In reply to Jeff King
Quoted 8 lines · Jeff King

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

#9 lore raw

Il giorno mar, 05/03/2019 alle 14.15 -0500, Jeff King ha scritto:

Quoted 24 lines · Jeff King
Quoted 5 lines

You can patch the Makefile, or just override it like:

  make LIBS='-lcrypto -lz'

Quoted 7 lines

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.

Quoted 7 lines

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 ;-)

#10 lore raw
Quoted 3 lines · Fabio Aiuto

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

#11 lore raw

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:

Quoted 15 lines · Fabio Aiuto
Quoted 5 lines

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

#14 lore raw
In reply to Jeff King

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:

Quoted 15 lines · Fabio Aiuto
Quoted 5 lines

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

#12 lore raw
In reply to Fabio Aiuto

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.

Quoted 22 lines · Fabio Aiuto

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:

Quoted 15 lines · Fabio Aiuto
Quoted 5 lines

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

#13 lore raw
Quoted 3 lines · Santiago Torres

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

#15 lore raw
In reply to Fabio Aiuto
Quoted 9 lines · Fabio Aiuto

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)

Quoted 8 lines
{
	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

#17 lore raw
In reply to a message not in the archive

[+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]

Quoted 11 lines · Fabio Aiuto

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

Quoted 1 line

.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

#18 lore raw

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:

Quoted 58 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]

Quoted 7 lines · Fabio Aiuto

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

Quoted 8 lines

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