BEAM files compiled from Erlang source files by erlc contain timestamps and the build path.
Detection
debbindiff sees .beam files that differ shortly after the word "time":
69 0000440: 0264 0004 7469 6d65 6806 6200 0007 de61 .d..timeh.b....a 70 0000450: 0c61 0661 1361 3661 1568 0264 0006 736f .a.a.a6a.h.d..so
This is in the Attr chunk of the file, which (I believe) could be anywhere (this typically doesn't make it into the diff).
Work-around
None yet.
Solution
erlc supports a +slim option which happens to omit the build time. However, it also drops a load of debug information (line number table, ...) from the file. Also, it's totally undocumented. This doesn't seem ideal.
Question to upstream about usage of the 'time' attribute
Alternatively: Patch erlc to honour DEB_BUILD_DATE, and make sure that's set?
Patch author (ChrisWest) doesn't really know Erlang:
- There's no date parsing code, so let's do that outside? This timestamp is UTC so need to be careful with timezones.
{match, ... re:run will exit the compiler if it doesn't match, which is probably what's wanted.
- Old behaviour is maintained if the environment variable isn't set
- erlang isn't whitespace sensitive so the totally bizarre tab/space mix isn't too worrying
--- a/lib/compiler/src/beam_asm.erl 2015-01-17 19:05:53.283257792 +0000
+++ b/lib/compiler/src/beam_asm.erl 2015-01-17 19:25:41.000000000 +0000
@@ -225,8 +225,14 @@
build_attributes(Opts, SourceFile, Attr, MD5) ->
Misc = case member(slim, Opts) of
false ->
- {{Y,Mo,D},{H,Mi,S}} = erlang:universaltime(),
- [{time,{Y,Mo,D,H,Mi,S}},{source,SourceFile}];
+ case os:getenv("DEB_BUILD_DATE") of
+ false ->
+ {{Y,Mo,D},{H,Mi,S}} = erlang:universaltime();
+ Date ->
+ {match, L} = re:run(Date, "(.*)-(.*)-(.*)T(.*):(.*):(.*)", [{capture, all_but_first, list}]),
+ [Y,Mo,D,H,Mi,S] = lists:map(fun erlang:list_to_integer/1, L)
+ end,
+ [{time,{Y,Mo,D,H,Mi,S}},{source,SourceFile}];
true -> []
end,
Compile = [{options,Opts},{version,?COMPILER_VSN}|Misc],With patch:
% ./erlc a.erl && sha1sum a.beam
9f050dc1b19f1fb3dc6cf5ec683d2f5dfd4099b8 a.beam
% ./erlc a.erl && sha1sum a.beam
041f6bb7492aae9331f82afbc39297659497c117 a.beam
% DEB_BUILD_DATE=2014-01-01T13:33:38 ./erlc a.erl && sha1sum a.beam
ee77fcb458195e99fd6d005c0bb06f767db6d1f0 a.beam
% DEB_BUILD_DATE=2014-01-01T13:33:38 ./erlc a.erl && sha1sum a.beam
ee77fcb458195e99fd6d005c0bb06f767db6d1f0 a.beam
% DEB_BUILD_DATE=2014-01-01T13:33:37 ./erlc a.erl && sha1sum a.beam
d9f323277ac1781a32bde5353b1d17770231274d a.beam
% DEB_BUILD_DATE=a ./erlc a.erl && sha1sum a.beam
a.erl: internal error in beam_asm;
crash reason: {badmatch,nomatch}
in function beam_asm:build_attributes/4 (beam_asm.erl, line 232)
in call from beam_asm:build_file/8 (beam_asm.erl, line 152)
in call from beam_asm:module/4 (beam_asm.erl, line 30)
in call from compile:beam_asm/1 (compile.erl, line 1320)
in call from compile:'-internal_comp/4-anonymous-1-'/2 (compile.erl, line 292)
in call from compile:fold_comp/3 (compile.erl, line 310)
in call from compile:internal_comp/4 (compile.erl, line 294)
in call from compile:'-do_compile/2-anonymous-0-'/2 (compile.erl, line 153)
% Simplified patch filed as https://bugs.debian.org/795834
