Skip to content

Commit

Permalink
gcc-wrapper: make __DATE__/__TIME__ deterministic
Browse files Browse the repository at this point in the history
...when NIX_ENFORCE_PURITY=1.

@vcunat corrected the date according to docs.
https://gcc.gnu.org/onlinedocs/cpp/Standard-Predefined-Macros.html
In order to handle the spaces well, the extraAfter array had to be
quoted more properly and appended by +=.
  • Loading branch information
alexanderkjeldaas authored and vcunat committed Sep 13, 2014
1 parent 7141303 commit aa119e1
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions pkgs/build-support/gcc-wrapper/gcc-wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,20 @@ fi
extraAfter=($NIX_CFLAGS_COMPILE)
extraBefore=()

# When enforcing purity, pretend gcc can't find the current date and
# time
if test "$NIX_ENFORCE_PURITY" = "1"; then
extraAfter+=('-D__DATE__=??? ?? ????'
'-D__TIME__=??:??:??'
-Wno-builtin-macro-redefined)
fi


if test "$dontLink" != "1"; then

# Add the flags that should only be passed to the compiler when
# linking.
extraAfter=(${extraAfter[@]} $NIX_CFLAGS_LINK)
extraAfter+=($NIX_CFLAGS_LINK)

# Add the flags that should be passed to the linker (and prevent
# `ld-wrapper' from adding NIX_LDFLAGS again).
Expand All @@ -97,9 +106,9 @@ if test "$dontLink" != "1"; then
done
for i in $NIX_LDFLAGS; do
if test "${i:0:3}" = "-L/"; then
extraAfter=(${extraAfter[@]} "$i")
extraAfter+=("$i")
else
extraAfter=(${extraAfter[@]} "-Wl,$i")
extraAfter+=("-Wl,$i")
fi
done
export NIX_LDFLAGS_SET=1
Expand Down Expand Up @@ -139,9 +148,9 @@ fi
# `-B' flags, since they confuse some programs. Deep bash magic to
# apply grep to stderr (by swapping stdin/stderr twice).
if test -z "$NIX_GCC_NEEDS_GREP"; then
@gccProg@ ${extraBefore[@]} "${params[@]}" ${extraAfter[@]}
@gccProg@ ${extraBefore[@]} "${params[@]}" "${extraAfter[@]}"
else
(@gccProg@ ${extraBefore[@]} "${params[@]}" ${extraAfter[@]} 3>&2 2>&1 1>&3- \
(@gccProg@ ${extraBefore[@]} "${params[@]}" "${extraAfter[@]}" 3>&2 2>&1 1>&3- \
| (grep -v 'file path prefix' || true); exit ${PIPESTATUS[0]}) 3>&2 2>&1 1>&3-
exit $?
fi

5 comments on commit aa119e1

@lucabrunox
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this broke unzip in staging: http://hydra.nixos.org/build/14219164/nixlog/1/raw

@edolstra
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be cleaner to just patch the implementation of __DATE__ and __TIME__ in gcc itself? Shouldn't be too hard.

@vcunat
Copy link
Member

@vcunat vcunat commented on aa119e1 Sep 16, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The breakages were IMO because of the missing quotes around the date string, so the expanded macro was not a string (I forgot those, I'm sorry). That should've been fixed by e766f0b (still OK after 552b105).

@vcunat
Copy link
Member

@vcunat vcunat commented on aa119e1 Sep 16, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The preprocessor flags could be shared by multiple compilers (which we currently don't do AFAIK). Anyway, a real general solution is LD_PRELOADing libfaketime or similar, which also seems to be among the patches in #2281 (31e433b).

@vcunat
Copy link
Member

@vcunat vcunat commented on aa119e1 Sep 16, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I confirmed locally that unzip builds in current staging (552b105).

Please sign in to comment.