threads / patch / 5283

patch, 6 partsSolaris does not support C99 format strings before version 10

Subject: [PATCH 2/6] Solaris does not support C99 format strings before version 10

## tl;dr

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

replies: 9people: 3as markdown or json

Dennis Stosberg· Aug 15, 2006, 09:00 UTC · lore

[PATCH 0/6] Configuration tweaks for Solaris

Hello,

The current configure script fails to generate a working configuration on Solaris for a number of different reasons. With these patches on the "next" branch "gmake clean configure && ./configure && gmake all test" completes on Solaris 9 with Sun CC 5.8 without errors.

The second patch may be suitable for the "maint" branch as well. Without it, at least t3800-mktag.sh fails.

Regards, Dennis

Dennis Stosberg· Aug 15, 2006, 09:01 UTC · re: Dennis Stosberg · lore

[PATCH 1/6] Solaris has strlcpy() at least since version 8

See http://docs.sun.com/app/docs/doc/816-3321/6m9k23sjk?a=view
Signed-off-by: Dennis Stosberg <dennis@stosberg.net>
---
 Makefile |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)
Show changes to Makefile +0 −1
diff --git a/Makefile b/Makefile
index 66c4fcc..495631a 100644
--- a/Makefile
+++ b/Makefile
@@ -338,7 +338,6 @@ ifeq ($(uname_S),SunOS)
 	NEEDS_NSL = YesPlease
 	SHELL_PATH = /bin/bash
 	NO_STRCASESTR = YesPlease
-	NO_STRLCPY = YesPlease
 	ifeq ($(uname_R),5.8)
 		NEEDS_LIBICONV = YesPlease
 		NO_UNSETENV = YesPlease
Dennis Stosberg· Aug 15, 2006, 09:01 UTC · re: Dennis Stosberg · lore
Signed-off-by: Dennis Stosberg <dennis@stosberg.net>
---
 Makefile |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
Show changes to Makefile +2 −0
diff --git a/Makefile b/Makefile
index 495631a..3cb6531 100644
--- a/Makefile
+++ b/Makefile
@@ -342,10 +342,12 @@ ifeq ($(uname_S),SunOS)
 		NEEDS_LIBICONV = YesPlease
 		NO_UNSETENV = YesPlease
 		NO_SETENV = YesPlease
+		NO_C99_FORMAT = YesPlease
 	endif
 	ifeq ($(uname_R),5.9)
 		NO_UNSETENV = YesPlease
 		NO_SETENV = YesPlease
+		NO_C99_FORMAT = YesPlease
 	endif
 	INSTALL = ginstall
 	TAR = gtar
Dennis Stosberg· Aug 15, 2006, 09:01 UTC · re: Dennis Stosberg · lore

[PATCH 3/6] Look for sockaddr_storage in sys/socket.h

On Solaris and the BSDs the definition of "struct sockaddr_storage" is not available from "netinet/in.h". On Solaris "sys/socket.h" is enough, at least OpenBSD needs "sys/types.h", too.

Using "sys/types.h" and "sys/socket.h" seems to be a more portable way.

Signed-off-by: Dennis Stosberg <dennis@stosberg.net>
---
 configure.ac |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
Show changes to configure.ac +4 −2
diff --git a/configure.ac b/configure.ac
index e890131..0321d43 100644
--- a/configure.ac
+++ b/configure.ac
@@ -181,8 +181,10 @@ # Define NO_SOCKADDR_STORAGE if your pla
 # sockaddr_storage.
 AC_CHECK_TYPE(struct sockaddr_storage,
 [NO_SOCKADDR_STORAGE=],
-[NO_SOCKADDR_STORAGE=YesPlease],
-[#include <netinet/in.h>])
+[NO_SOCKADDR_STORAGE=YesPlease],[
+#include <sys/types.h>
+#include <sys/socket.h>
+])
 AC_SUBST(NO_SOCKADDR_STORAGE)
 #
 # Define NO_IPV6 if you lack IPv6 support and getaddrinfo().
Dennis Stosberg· Aug 15, 2006, 09:01 UTC · re: Dennis Stosberg · lore

[PATCH 4/6] Fix detection of ipv6 on Solaris

The configuration script detects whether linking with -lsocket is necessary but doesn't add -lsocket to LIBS. This lets the ipv6 test fail.

Signed-off-by: Dennis Stosberg <dennis@stosberg.net>
---
 configure.ac |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
Show changes to configure.ac +1 −0
diff --git a/configure.ac b/configure.ac
index 0321d43..36f9cd9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -154,6 +154,7 @@ AC_CHECK_LIB([c], [socket],
 [NEEDS_SOCKET=],
 [NEEDS_SOCKET=YesPlease])
 AC_SUBST(NEEDS_SOCKET)
+test -n "$NEEDS_SOCKET" && LIBS="$LIBS -lsocket"
 
 
 ## Checks for header files.
Dennis Stosberg· Aug 15, 2006, 09:01 UTC · re: Dennis Stosberg · lore

[PATCH 5/6] On Solaris nanosleep() is not in libc but in librt

Signed-off-by: Dennis Stosberg <dennis@stosberg.net>
---
 Makefile      |   11 +++++++++--
 config.mak.in |    1 +
 configure.ac  |   10 ++++++++--
 3 files changed, 18 insertions(+), 4 deletions(-)
Show changes to 3 files +18 −4

Makefile, config.mak.in, configure.ac

diff --git a/Makefile b/Makefile
index 3cb6531..d352901 100644
--- a/Makefile
+++ b/Makefile
@@ -67,8 +67,10 @@ # Define NEEDS_SSL_WITH_CRYPTO if you ne
 #
 # Define NEEDS_LIBICONV if linking with libc is not enough (Darwin).
 #
-# Define NEEDS_SOCKET if linking with libc is not enough (SunOS,
-# Patrick Mauritz).
+# Define NEEDS_SOCKET if linking with libc is not enough for socket()
+# (SunOS, Patrick Mauritz).
+#
+# Define NEEDS_RT if linking with libc is not enough for nanosleep() (SunOS)
 #
 # Define NO_MMAP if you want to avoid mmap.
 #
@@ -336,6 +338,7 @@ endif
 ifeq ($(uname_S),SunOS)
 	NEEDS_SOCKET = YesPlease
 	NEEDS_NSL = YesPlease
+	NEEDS_RT = YesPlease
 	SHELL_PATH = /bin/bash
 	NO_STRCASESTR = YesPlease
 	ifeq ($(uname_R),5.8)
@@ -479,6 +482,10 @@ ifdef NEEDS_NSL
 	EXTLIBS += -lnsl
 	SIMPLE_LIB += -lnsl
 endif
+ifdef NEEDS_RT
+	EXTLIBS += -lrt
+	SIMPLE_LIB += -lrt
+endif
 ifdef NO_D_TYPE_IN_DIRENT
 	BASIC_CFLAGS += -DNO_D_TYPE_IN_DIRENT
 endif
diff --git a/config.mak.in b/config.mak.in
index 369e611..038767e 100644
--- a/config.mak.in
+++ b/config.mak.in
@@ -29,6 +29,7 @@ NO_CURL=@NO_CURL@
 NO_EXPAT=@NO_EXPAT@
 NEEDS_LIBICONV=@NEEDS_LIBICONV@
 NEEDS_SOCKET=@NEEDS_SOCKET@
+NEEDS_RT=@NEEDS_RT@
 NO_D_INO_IN_DIRENT=@NO_D_INO_IN_DIRENT@
 NO_D_TYPE_IN_DIRENT=@NO_D_TYPE_IN_DIRENT@
 NO_SOCKADDR_STORAGE=@NO_SOCKADDR_STORAGE@
diff --git a/configure.ac b/configure.ac
index 36f9cd9..6f1d87a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -148,13 +148,19 @@ AC_CHECK_LIB([c], [iconv],
 [NEEDS_LIBICONV=YesPlease])
 AC_SUBST(NEEDS_LIBICONV)
 #
-# Define NEEDS_SOCKET if linking with libc is not enough (SunOS,
-# Patrick Mauritz).
+# Define NEEDS_SOCKET if linking with libc is not enough for socket()
+# (SunOS, Patrick Mauritz).
 AC_CHECK_LIB([c], [socket],
 [NEEDS_SOCKET=],
 [NEEDS_SOCKET=YesPlease])
 AC_SUBST(NEEDS_SOCKET)
 test -n "$NEEDS_SOCKET" && LIBS="$LIBS -lsocket"
+#
+# Define NEEDS_RT if linking with libc is not enough for nanosleep (SunOS)
+AC_CHECK_LIB([c], [nanosleep],
+[NEEDS_RT=],
+[NEEDS_RT=YesPlease])
+AC_SUBST(NEEDS_RT)
 
 
 ## Checks for header files.
Junio C Hamano· Aug 15, 2006, 10:35 UTC · re: Dennis Stosberg · lore

Re: [PATCH 5/6] On Solaris nanosleep() is not in libc but in librt

Dennis Stosberg <dennis@stosberg.net> writes:
Show 6 quoted lines
> -# Define NEEDS_SOCKET if linking with libc is not enough (SunOS,
> -# Patrick Mauritz).
> +# Define NEEDS_SOCKET if linking with libc is not enough for socket()
> +# (SunOS, Patrick Mauritz).
> +#
> +# Define NEEDS_RT if linking with libc is not enough for nanosleep() (SunOS)

Ah, nanosleep(2) was my fault, and we should be able to just use straight sleep(3) there. The purpose of the loop is to wait until the next filesystem timestamp granularity, and the code uses subsecond sleep in the hope that it can shorten the delay to 0.5 seconds on average instead of a full second.

How exotic is -lrt on SunOS? I suspect it is not worth depending on it only for that single use in read-cache.c

We might want to yank out the whole "racy-git avoidance is costly later so let's delay writing the index out" codepath later, but that is a separate issue and needs some testing on large trees to figure it out. After playing with the kernel tree, I have a feeling that the whole thing may not be worth it.

In any case, an obvious tentative patch is here.
Show changes to read-cache.c +1 −5
diff --git a/read-cache.c b/read-cache.c
index b18f9f7..ec4dd5a 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -5,7 +5,6 @@
  */
 #include "cache.h"
 #include "cache-tree.h"
-#include <time.h>
 
 /* Index extensions.
  *
@@ -1033,11 +1032,8 @@ #if 0
 			fprintf(stderr, "now        %lu\n", now);
 #endif
 			while (!fstat(newfd, &st) && st.st_mtime <= now) {
-				struct timespec rq, rm;
 				off_t where = lseek(newfd, 0, SEEK_CUR);
-				rq.tv_sec = 0;
-				rq.tv_nsec = 250000000;
-				nanosleep(&rq, &rm);
+				sleep(1);
 				if ((where == (off_t) -1) ||
 				    (write(newfd, "", 1) != 1) ||
 				    (lseek(newfd, -1, SEEK_CUR) != where) ||
Alex Riesen· Aug 15, 2006, 11:18 UTC · re: Junio C Hamano · lore

Re: [PATCH 5/6] On Solaris nanosleep() is not in libc but in librt

On 8/15/06, Junio C Hamano <junkio@cox.net> wrote:
Show 12 quoted lines
> > -# Define NEEDS_SOCKET if linking with libc is not enough (SunOS,
> > -# Patrick Mauritz).
> > +# Define NEEDS_SOCKET if linking with libc is not enough for socket()
> > +# (SunOS, Patrick Mauritz).
> > +#
> > +# Define NEEDS_RT if linking with libc is not enough for nanosleep() (SunOS)
>
> Ah, nanosleep(2) was my fault, and we should be able to just use
> straight sleep(3) there.  The purpose of the loop is to wait
> until the next filesystem timestamp granularity, and the code
> uses subsecond sleep in the hope that it can shorten the delay
> to 0.5 seconds on average instead of a full second.

Was it not SunOS where sleep was implemented by means of SIGALRM? Besides, we still can shorten the delay by using select(2).

Junio C Hamano· Aug 15, 2006, 20:12 UTC · re: Junio C Hamano · lore

[PATCH] Documentation/technical/racy-git.txt

Signed-off-by: Junio C Hamano <junkio@cox.net>
---
   Junio C Hamano <junkio@cox.net> writes:
   > We might want to yank out the whole "racy-git avoidance is
   > costly later so let's delay writing the index out" codepath
   > later, but that is a separate issue and needs some testing on
   > large trees to figure it out.  After playing with the kernel
   > tree, I have a feeling that the whole thing may not be worth
   > it.
   Addressed to Linus because he originally brought up this issue
   in <Pine.LNX.4.64.0607310945490.4168@g5.osdl.org>, Johannes
   CC'ed because he had some comments earlier on the same topic
   and he is generally a good person to talk to when I have
   doubts on issues ;-).
 Documentation/technical/racy-git.txt |  193 ++++++++++++++++++++++++++++++++++
 1 files changed, 193 insertions(+), 0 deletions(-)
Show changes to Documentation/technical/racy-git.txt +193 −0
diff --git a/Documentation/technical/racy-git.txt b/Documentation/technical/racy-git.txt
new file mode 100644
index 0000000..7597d04
--- /dev/null
+++ b/Documentation/technical/racy-git.txt
@@ -0,0 +1,193 @@
+Use of index and Racy git problem
+=================================
+
+Background
+----------
+
+The index is one of the most important data structure in git.
+It represents a virtual working tree state by recording list of
+paths and their object names and serves as a staging area to
+write out the next tree object to be committed.  The state is
+"virtual" in the sense that it does not necessarily have to, and
+often does not, match the files in the working tree.
+
+There are cases git needs to examine the differences between the
+virtual working tree state in the index and the files in the
+working tree.  The most obvious case is when the user asks `git
+diff` (or its low level implementation, `git diff-files`) or
+`git-ls-files --modified`.  In addition, git internally checks
+if the files in the working tree is different from what are
+recorded in the index to avoid stomping on local changes in them
+during patch application, switching branches, and merging.
+
+In order to speed up this comparison between the files in the
+working tree and the index entries, the index entries record the
+information obtained from the filesystem via `lstat(2)` system
+call when they were last updated.  When checking if they differ,
+git first runs `lstat(2)` on the files and compare the result
+with this information (this is what was originally done by the
+`ce_match_stat()` function, which the current code does in
+`ce_match_stat_basic()` function).  If some of these "cached
+stat information" fields do not match, git can tell that the
+files are modified without even looking at their contents.
+
+Note: not all members in `struct stat` obtained via `lstat(2)`
+are used for this comparison.  For example, `st_atime` obviously
+is not useful.  Currently, git compares the file type (regular
+files vs symbolic links) and executable bits (only for regular
+files) from `st_mode` member, `st_mtime` and `st_ctime`
+timestamps, `st_uid`, `st_gid`, `st_ino`, and `st_size` members.
+With a `USE_STDEV` compile-time option, `st_dev` is also
+compared, but this is not enabled by default because this member
+is not stable on network filesystems.  With `USE_NSEC`
+compile-time option, `st_mtim.tv_nsec` and `st_ctim.tv_nsec`
+members are also compared, but this is not enabled by default
+because the value of this member becomes meaningless once the
+inode is evicted from the inode cache on filesystems that do not
+store it on disk.
+
+
+Racy git
+--------
+
+There is one slight problem with the optimization based on the
+cached stat information.  Consider this sequence:
+
+  $ git update-index 'foo'
+  : modify 'foo' in-place without changing its size
+
+The first `update-index` computes the object name of the
+contents of file `foo` and updates the index entry for `foo`
+along with the `struct stat` information.  If the modification
+that follows it happens very fast so that the file's `st_mtime`
+timestamp does not change, after this sequence, the cached stat
+information the index entry records still exactly match what you
+can obtain from the filesystem, but the file `foo` is modified.
+This way, git can incorrectly think files in the working tree
+are unmodified even though they actually are.  This is called
+the "racy git" problem (discovered by Pasky), and the entries
+that appear clean when they may not be because of this problem
+are called "racily clean".
+
+To avoid this problem, git does two things:
+
+. When the cached stat information says the file has not been
+  modified, and the `st_mtime` is the same as (or newer than)
+  the timestamp of the index file itself (which is the time `git
+  update-index foo` finished running in the above example), it
+  also compares the contents with the object registered in the
+  index entry to make sure they match.
+
+. When the index file is updated that contains racily clean
+  entries, cached `st_size` information is truncated to zero
+  before writing a new version of the index file.
+
+Because the index file itself is written after collecting all
+the stat information from updated paths, `st_mtime` timestamp of
+it is usually the same as or newer than any of the paths the
+index contains.  And no matter how quick the modification that
+follows `git update-index foo` finishes, the resulting
+`st_mtime` timestamp on `foo` cannot get the timestamp earlier
+than the index file.  Therefore, index entries that can be
+racily clean are limited to the ones that have the same
+timestamp as the index file itself.
+
+The callers that want to check if an index entry matches the
+corresponding file in the working tree continue to call
+`ce_match_stat()`, but with this change, `ce_match_stat()` uses
+`ce_modified_check_fs()` to see if racily clean ones are
+actually clean after comparing the cached stat information using
+`ce_match_stat_basic()`.
+
+The problem the latter solves is this sequence:
+
+  $ git update-index 'foo'
+  : modify 'foo' in-place without changing its size
+  : wait for enough time
+  $ git update-index 'bar'
+
+Without the latter, the timestamp of the index file gets a newer
+value, and falsely clean entry `foo` would not be caught by the
+timestamp comparison check done with the former logic anymore.
+The latter makes sure that the cached stat information for `foo`
+would never match with the file in the working tree, so later
+checks by `ce_match_stat_basic()` would report the index entry
+does not match the file and git does not have to fall back on more
+expensive `ce_modified_check_fs()`.
+
+
+Runtime penalty
+---------------
+
+The runtime penalty of falling back to `ce_modified_check_fs()`
+from `ce_match_stat()` can be very expensive when there are many
+racily clean entries.  An obvious way to artificially create
+this situation is to give the same timestamp to all the files in
+the working tree in a large project, run `git update-index` on
+them, and give the same timestamp to the index file:
+
+  $ date >.datestamp
+  $ git ls-files | xargs touch -r .datestamp
+  $ git ls-files | git update-index --stdin
+  $ touch -r .datestamp .git/index
+
+This will make all index entries racily clean.  The linux-2.6
+project, for example, there are over 20,000 files in the working
+tree.  On my Athron 64X2 3800+, after the above:
+
+  $ /usr/bin/time git diff-files
+  1.68user 0.54system 0:02.22elapsed 100%CPU (0avgtext+0avgdata 0maxresident)k
+  0inputs+0outputs (0major+67111minor)pagefaults 0swaps
+  $ git update-index MAINTAINERS
+  $ /usr/bin/time git diff-files
+  0.02user 0.12system 0:00.14elapsed 100%CPU (0avgtext+0avgdata 0maxresident)k
+  0inputs+0outputs (0major+935minor)pagefaults 0swaps
+
+Running `git update-index` in the middle checked the racily
+clean entries, and left the cached `st_mtime` for all the paths
+intact because they were actually clean (so this step took about
+the same amount of time as the first `git diff-files`).  After
+that, they are not racily clean anymore but are truly clean, so
+the second invocation of `git diff-files` fully took advantage
+of the cached stat information.
+
+
+Avoiding runtime penalty
+------------------------
+
+In order to avoid the above runtime penalty, the recent "master"
+branch (post 1.4.2) has a code that makes sure the index file
+gets timestamp newer than the youngest files in the index when
+there are many young files with the same timestamp as the
+resulting index file would otherwise would have by waiting
+before finishing writing the index file out.
+
+I suspect that in practice the situation where many paths in the
+index are all racily clean is quite rare.  The only code paths
+that can record recent timestamp for large number of paths I
+know of are:
+
+. Initial `git add .` of a large project.
+
+. `git checkout` of a large project from an empty index into an
+  unpopulated working tree.
+
+Note: switching branches with `git checkout` keeps the cached
+stat information of existing working tree files that are the
+same between the current branch and the new branch, which are
+all older than the resulting index file, and they will not
+become racily clean.  Only the files that are actually checked
+out can become racily clean.
+
+In a large project where raciness avoidance cost really matters,
+however, the initial computation of all object names in the
+index takes more than one second, and the index file is written
+out after all that happens.  Therefore the timestamp of the
+index file will be more than one seconds later than the the
+youngest file in the working tree.  This means that in these
+cases there actually will not be any racily clean entry in
+the resulting index.
+
+So in summary I think we should not worry about avoiding the
+runtime penalty and get rid of the "wait before finishing
+writing" code out.
-- 
1.4.2.g59bb
Dennis Stosberg· Aug 15, 2006, 09:01 UTC · re: Dennis Stosberg · lore

[PATCH 6/6] Fix compilation with Sun CC

- Add the CFLAGS variable to config.mak.in to override the Makefile's
  default, which is gcc-specific and won't work with Sun CC.
- Prefer "cc" over "gcc", because Pasky's Git.pm will not compile with gcc
  on Solaris at all. On Linux and the free BSDs "cc" is linked to "gcc"
  anyway.
- Set correct flag to generate position-independent code.
- Add "-xO3" (= use default optimization level) to CFLAGS.
Signed-off-by: Dennis Stosberg <dennis@stosberg.net>
---
 Makefile      |    6 +++++-
 config.mak.in |    2 ++
 configure.ac  |    9 ++++++++-
 3 files changed, 15 insertions(+), 2 deletions(-)
Show changes to 3 files +15 −2

Makefile, config.mak.in, configure.ac

diff --git a/Makefile b/Makefile
index d352901..aeefc4e 100644
--- a/Makefile
+++ b/Makefile
@@ -114,6 +114,7 @@ uname_P := $(shell sh -c 'uname -p 2>/de
 # CFLAGS and LDFLAGS are for the users to override from the command line.
 
 CFLAGS = -g -O2 -Wall
+PIC_FLAG = -fPIC
 LDFLAGS =
 ALL_CFLAGS = $(CFLAGS)
 ALL_LDFLAGS = $(LDFLAGS)
@@ -408,6 +409,9 @@ endif
 ifneq (,$(findstring arm,$(uname_M)))
 	ARM_SHA1 = YesPlease
 endif
+ifeq ($(uname_M),sun4u)
+	USE_PIC = YesPlease
+endif
 ifeq ($(uname_M),x86_64)
 	USE_PIC = YesPlease
 endif
@@ -554,7 +558,7 @@ endif
 endif
 endif
 ifdef USE_PIC
-	ALL_CFLAGS += -fPIC
+	ALL_CFLAGS += $(PIC_FLAG)
 endif
 ifdef NO_ACCURATE_DIFF
 	BASIC_CFLAGS += -DNO_ACCURATE_DIFF
diff --git a/config.mak.in b/config.mak.in
index 038767e..1fd5f7e 100644
--- a/config.mak.in
+++ b/config.mak.in
@@ -2,6 +2,8 @@ # git Makefile configuration, included i
 # @configure_input@
 
 CC = @CC@
+CFLAGS = @CFLAGS@
+PIC_FLAG = @PIC_FLAG@
 AR = @AR@
 TAR = @TAR@
 #INSTALL = @INSTALL@		# needs install-sh or install.sh in sources
diff --git a/configure.ac b/configure.ac
index 6f1d87a..427ac23 100644
--- a/configure.ac
+++ b/configure.ac
@@ -95,7 +95,14 @@ AC_SUBST(PYTHON_PATH)
 ## Checks for programs.
 AC_MSG_NOTICE([CHECKS for programs])
 #
-AC_PROG_CC
+AC_PROG_CC([cc gcc])
+if test -n "$GCC"; then
+	PIC_FLAG="-fPIC"
+else
+	AC_CHECK_DECL(__SUNPRO_C, [CFLAGS="$CFLAGS -xO3"; PIC_FLAG="-KPIC"])
+fi
+AC_SUBST(PIC_FLAG)
+
 #AC_PROG_INSTALL		# needs install-sh or install.sh in sources
 AC_CHECK_TOOL(AR, ar, :)
 AC_CHECK_PROGS(TAR, [gtar tar])

← back to recent threads