Skip to content

Commit 9126f00

Browse files
Nicolas Pitrespearce
authored andcommitted
fix openssl headers conflicting with custom SHA1 implementations
On ARM I have the following compilation errors: CC fast-import.o In file included from cache.h:8, from builtin.h:6, from fast-import.c:142: arm/sha1.h:14: error: conflicting types for 'SHA_CTX' /usr/include/openssl/sha.h:105: error: previous declaration of 'SHA_CTX' was here arm/sha1.h:16: error: conflicting types for 'SHA1_Init' /usr/include/openssl/sha.h:115: error: previous declaration of 'SHA1_Init' was here arm/sha1.h:17: error: conflicting types for 'SHA1_Update' /usr/include/openssl/sha.h:116: error: previous declaration of 'SHA1_Update' was here arm/sha1.h:18: error: conflicting types for 'SHA1_Final' /usr/include/openssl/sha.h:117: error: previous declaration of 'SHA1_Final' was here make: *** [fast-import.o] Error 1 This is because openssl header files are always included in git-compat-util.h since commit 684ec6c whenever NO_OPENSSL is not set, which somehow brings in <openssl/sha1.h> clashing with the custom ARM version. Compilation of git is probably broken on PPC too for the same reason. Turns out that the only file requiring openssl/ssl.h and openssl/err.h is imap-send.c. But only moving those problematic includes there doesn't solve the issue as it also includes cache.h which brings in the conflicting local SHA1 header file. As suggested by Jeff King, the best solution is to rename our references to SHA1 functions and structure to something git specific, and define those according to the implementation used. Signed-off-by: Nicolas Pitre <[email protected]> Signed-off-by: Shawn O. Pearce <[email protected]>
1 parent 120a385 commit 9126f00

24 files changed

+162
-141
lines changed

arm/sha1.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
#include <string.h>
99
#include "sha1.h"
1010

11-
extern void sha_transform(uint32_t *hash, const unsigned char *data, uint32_t *W);
11+
extern void arm_sha_transform(uint32_t *hash, const unsigned char *data, uint32_t *W);
1212

13-
void SHA1_Init(SHA_CTX *c)
13+
void arm_SHA1_Init(arm_SHA_CTX *c)
1414
{
1515
c->len = 0;
1616
c->hash[0] = 0x67452301;
@@ -20,7 +20,7 @@ void SHA1_Init(SHA_CTX *c)
2020
c->hash[4] = 0xc3d2e1f0;
2121
}
2222

23-
void SHA1_Update(SHA_CTX *c, const void *p, unsigned long n)
23+
void arm_SHA1_Update(arm_SHA_CTX *c, const void *p, unsigned long n)
2424
{
2525
uint32_t workspace[80];
2626
unsigned int partial;
@@ -32,12 +32,12 @@ void SHA1_Update(SHA_CTX *c, const void *p, unsigned long n)
3232
if (partial) {
3333
done = 64 - partial;
3434
memcpy(c->buffer + partial, p, done);
35-
sha_transform(c->hash, c->buffer, workspace);
35+
arm_sha_transform(c->hash, c->buffer, workspace);
3636
partial = 0;
3737
} else
3838
done = 0;
3939
while (n >= done + 64) {
40-
sha_transform(c->hash, p + done, workspace);
40+
arm_sha_transform(c->hash, p + done, workspace);
4141
done += 64;
4242
}
4343
} else
@@ -46,7 +46,7 @@ void SHA1_Update(SHA_CTX *c, const void *p, unsigned long n)
4646
memcpy(c->buffer + partial, p + done, n - done);
4747
}
4848

49-
void SHA1_Final(unsigned char *hash, SHA_CTX *c)
49+
void arm_SHA1_Final(unsigned char *hash, arm_SHA_CTX *c)
5050
{
5151
uint64_t bitlen;
5252
uint32_t bitlen_hi, bitlen_lo;
@@ -57,7 +57,7 @@ void SHA1_Final(unsigned char *hash, SHA_CTX *c)
5757
bitlen = c->len << 3;
5858
offset = c->len & 0x3f;
5959
padlen = ((offset < 56) ? 56 : (64 + 56)) - offset;
60-
SHA1_Update(c, padding, padlen);
60+
arm_SHA1_Update(c, padding, padlen);
6161

6262
bitlen_hi = bitlen >> 32;
6363
bitlen_lo = bitlen & 0xffffffff;
@@ -69,7 +69,7 @@ void SHA1_Final(unsigned char *hash, SHA_CTX *c)
6969
bits[5] = bitlen_lo >> 16;
7070
bits[6] = bitlen_lo >> 8;
7171
bits[7] = bitlen_lo;
72-
SHA1_Update(c, bits, 8);
72+
arm_SHA1_Update(c, bits, 8);
7373

7474
for (i = 0; i < 5; i++) {
7575
uint32_t v = c->hash[i];

arm/sha1.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,17 @@
77

88
#include <stdint.h>
99

10-
typedef struct sha_context {
10+
typedef struct {
1111
uint64_t len;
1212
uint32_t hash[5];
1313
unsigned char buffer[64];
14-
} SHA_CTX;
14+
} arm_SHA_CTX;
1515

16-
void SHA1_Init(SHA_CTX *c);
17-
void SHA1_Update(SHA_CTX *c, const void *p, unsigned long n);
18-
void SHA1_Final(unsigned char *hash, SHA_CTX *c);
16+
void arm_SHA1_Init(arm_SHA_CTX *c);
17+
void arm_SHA1_Update(arm_SHA_CTX *c, const void *p, unsigned long n);
18+
void arm_SHA1_Final(unsigned char *hash, arm_SHA_CTX *c);
19+
20+
#define git_SHA_CTX arm_SHA_CTX
21+
#define git_SHA1_Init arm_SHA1_Init
22+
#define git_SHA1_Update arm_SHA1_Update
23+
#define git_SHA1_Final arm_SHA1_Final

arm/sha1_arm.S

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010
*/
1111

1212
.text
13-
.globl sha_transform
13+
.globl arm_sha_transform
1414

1515
/*
1616
* void sha_transform(uint32_t *hash, const unsigned char *data, uint32_t *W);
1717
*
1818
* note: the "data" pointer may be unaligned.
1919
*/
2020

21-
sha_transform:
21+
arm_sha_transform:
2222

2323
stmfd sp!, {r4 - r8, lr}
2424

builtin-unpack-objects.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ static const char unpack_usage[] = "git unpack-objects [-n] [-q] [-r] [--strict]
1919
static unsigned char buffer[4096];
2020
static unsigned int offset, len;
2121
static off_t consumed_bytes;
22-
static SHA_CTX ctx;
22+
static git_SHA_CTX ctx;
2323

2424
/*
2525
* When running under --strict mode, objects whose reachability are
@@ -59,7 +59,7 @@ static void *fill(int min)
5959
if (min > sizeof(buffer))
6060
die("cannot fill %d bytes", min);
6161
if (offset) {
62-
SHA1_Update(&ctx, buffer, offset);
62+
git_SHA1_Update(&ctx, buffer, offset);
6363
memmove(buffer, buffer + offset, len);
6464
offset = 0;
6565
}
@@ -539,10 +539,10 @@ int cmd_unpack_objects(int argc, const char **argv, const char *prefix)
539539
/* We don't take any non-flag arguments now.. Maybe some day */
540540
usage(unpack_usage);
541541
}
542-
SHA1_Init(&ctx);
542+
git_SHA1_Init(&ctx);
543543
unpack_all();
544-
SHA1_Update(&ctx, buffer, offset);
545-
SHA1_Final(sha1, &ctx);
544+
git_SHA1_Update(&ctx, buffer, offset);
545+
git_SHA1_Final(sha1, &ctx);
546546
if (strict)
547547
write_rest();
548548
if (hashcmp(fill(20), sha1))

cache.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,14 @@
66
#include "hash.h"
77

88
#include SHA1_HEADER
9-
#include <zlib.h>
9+
#ifndef git_SHA_CTX
10+
#define git_SHA_CTX SHA_CTX
11+
#define git_SHA1_Init SHA1_Init
12+
#define git_SHA1_Update SHA1_Update
13+
#define git_SHA1_Final SHA1_Final
14+
#endif
1015

16+
#include <zlib.h>
1117
#if defined(NO_DEFLATE_BOUND) || ZLIB_VERNUM < 0x1200
1218
#define deflateBound(c,s) ((s) + (((s) + 7) >> 3) + (((s) + 63) >> 6) + 11)
1319
#endif

csum-file.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ int sha1close(struct sha1file *f, unsigned char *result, unsigned int flags)
3636
unsigned offset = f->offset;
3737

3838
if (offset) {
39-
SHA1_Update(&f->ctx, f->buffer, offset);
39+
git_SHA1_Update(&f->ctx, f->buffer, offset);
4040
sha1flush(f, f->buffer, offset);
4141
f->offset = 0;
4242
}
43-
SHA1_Final(f->buffer, &f->ctx);
43+
git_SHA1_Final(f->buffer, &f->ctx);
4444
if (result)
4545
hashcpy(result, f->buffer);
4646
if (flags & (CSUM_CLOSE | CSUM_FSYNC)) {
@@ -82,7 +82,7 @@ int sha1write(struct sha1file *f, void *buf, unsigned int count)
8282
buf = (char *) buf + nr;
8383
left -= nr;
8484
if (!left) {
85-
SHA1_Update(&f->ctx, data, offset);
85+
git_SHA1_Update(&f->ctx, data, offset);
8686
sha1flush(f, data, offset);
8787
offset = 0;
8888
}
@@ -105,7 +105,7 @@ struct sha1file *sha1fd_throughput(int fd, const char *name, struct progress *tp
105105
f->tp = tp;
106106
f->name = name;
107107
f->do_crc = 0;
108-
SHA1_Init(&f->ctx);
108+
git_SHA1_Init(&f->ctx);
109109
return f;
110110
}
111111

csum-file.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ struct progress;
77
struct sha1file {
88
int fd;
99
unsigned int offset;
10-
SHA_CTX ctx;
10+
git_SHA_CTX ctx;
1111
off_t total;
1212
struct progress *tp;
1313
const char *name;

diff.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3087,7 +3087,7 @@ static void diff_summary(FILE *file, struct diff_filepair *p)
30873087
}
30883088

30893089
struct patch_id_t {
3090-
SHA_CTX *ctx;
3090+
git_SHA_CTX *ctx;
30913091
int patchlen;
30923092
};
30933093

@@ -3115,7 +3115,7 @@ static void patch_id_consume(void *priv, char *line, unsigned long len)
31153115

31163116
new_len = remove_space(line, len);
31173117

3118-
SHA1_Update(data->ctx, line, new_len);
3118+
git_SHA1_Update(data->ctx, line, new_len);
31193119
data->patchlen += new_len;
31203120
}
31213121

@@ -3124,11 +3124,11 @@ static int diff_get_patch_id(struct diff_options *options, unsigned char *sha1)
31243124
{
31253125
struct diff_queue_struct *q = &diff_queued_diff;
31263126
int i;
3127-
SHA_CTX ctx;
3127+
git_SHA_CTX ctx;
31283128
struct patch_id_t data;
31293129
char buffer[PATH_MAX * 4 + 20];
31303130

3131-
SHA1_Init(&ctx);
3131+
git_SHA1_Init(&ctx);
31323132
memset(&data, 0, sizeof(struct patch_id_t));
31333133
data.ctx = &ctx;
31343134

@@ -3190,7 +3190,7 @@ static int diff_get_patch_id(struct diff_options *options, unsigned char *sha1)
31903190
len2, p->two->path,
31913191
len1, p->one->path,
31923192
len2, p->two->path);
3193-
SHA1_Update(&ctx, buffer, len1);
3193+
git_SHA1_Update(&ctx, buffer, len1);
31943194

31953195
xpp.flags = XDF_NEED_MINIMAL;
31963196
xecfg.ctxlen = 3;
@@ -3199,7 +3199,7 @@ static int diff_get_patch_id(struct diff_options *options, unsigned char *sha1)
31993199
&xpp, &xecfg, &ecb);
32003200
}
32013201

3202-
SHA1_Final(sha1, &ctx);
3202+
git_SHA1_Final(sha1, &ctx);
32033203
return 0;
32043204
}
32053205

fast-import.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ static int oecmp (const void *a_, const void *b_)
845845
static char *create_index(void)
846846
{
847847
static char tmpfile[PATH_MAX];
848-
SHA_CTX ctx;
848+
git_SHA_CTX ctx;
849849
struct sha1file *f;
850850
struct object_entry **idx, **c, **last, *e;
851851
struct object_entry_pool *o;
@@ -882,17 +882,17 @@ static char *create_index(void)
882882
idx_fd = xmkstemp(tmpfile);
883883
f = sha1fd(idx_fd, tmpfile);
884884
sha1write(f, array, 256 * sizeof(int));
885-
SHA1_Init(&ctx);
885+
git_SHA1_Init(&ctx);
886886
for (c = idx; c != last; c++) {
887887
uint32_t offset = htonl((*c)->offset);
888888
sha1write(f, &offset, 4);
889889
sha1write(f, (*c)->sha1, sizeof((*c)->sha1));
890-
SHA1_Update(&ctx, (*c)->sha1, 20);
890+
git_SHA1_Update(&ctx, (*c)->sha1, 20);
891891
}
892892
sha1write(f, pack_data->sha1, sizeof(pack_data->sha1));
893893
sha1close(f, NULL, CSUM_FSYNC);
894894
free(idx);
895-
SHA1_Final(pack_data->sha1, &ctx);
895+
git_SHA1_Final(pack_data->sha1, &ctx);
896896
return tmpfile;
897897
}
898898

@@ -1033,15 +1033,15 @@ static int store_object(
10331033
unsigned char hdr[96];
10341034
unsigned char sha1[20];
10351035
unsigned long hdrlen, deltalen;
1036-
SHA_CTX c;
1036+
git_SHA_CTX c;
10371037
z_stream s;
10381038

10391039
hdrlen = sprintf((char*)hdr,"%s %lu", typename(type),
10401040
(unsigned long)dat->len) + 1;
1041-
SHA1_Init(&c);
1042-
SHA1_Update(&c, hdr, hdrlen);
1043-
SHA1_Update(&c, dat->buf, dat->len);
1044-
SHA1_Final(sha1, &c);
1041+
git_SHA1_Init(&c);
1042+
git_SHA1_Update(&c, hdr, hdrlen);
1043+
git_SHA1_Update(&c, dat->buf, dat->len);
1044+
git_SHA1_Final(sha1, &c);
10451045
if (sha1out)
10461046
hashcpy(sha1out, sha1);
10471047

http-push.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ struct transfer_request
126126
char errorstr[CURL_ERROR_SIZE];
127127
long http_code;
128128
unsigned char real_sha1[20];
129-
SHA_CTX c;
129+
git_SHA_CTX c;
130130
z_stream stream;
131131
int zret;
132132
int rename;
@@ -209,7 +209,7 @@ static size_t fwrite_sha1_file(void *ptr, size_t eltsize, size_t nmemb,
209209
request->stream.next_out = expn;
210210
request->stream.avail_out = sizeof(expn);
211211
request->zret = inflate(&request->stream, Z_SYNC_FLUSH);
212-
SHA1_Update(&request->c, expn,
212+
git_SHA1_Update(&request->c, expn,
213213
sizeof(expn) - request->stream.avail_out);
214214
} while (request->stream.avail_in && request->zret == Z_OK);
215215
data_received++;
@@ -270,7 +270,7 @@ static void start_fetch_loose(struct transfer_request *request)
270270

271271
inflateInit(&request->stream);
272272

273-
SHA1_Init(&request->c);
273+
git_SHA1_Init(&request->c);
274274

275275
url = xmalloc(strlen(remote->url) + 50);
276276
request->url = xmalloc(strlen(remote->url) + 50);
@@ -310,7 +310,7 @@ static void start_fetch_loose(struct transfer_request *request)
310310
if (prev_read == -1) {
311311
memset(&request->stream, 0, sizeof(request->stream));
312312
inflateInit(&request->stream);
313-
SHA1_Init(&request->c);
313+
git_SHA1_Init(&request->c);
314314
if (prev_posn>0) {
315315
prev_posn = 0;
316316
lseek(request->local_fileno, 0, SEEK_SET);
@@ -742,7 +742,7 @@ static void finish_request(struct transfer_request *request)
742742
fprintf(stderr, "Warning: requested range invalid; we may already have all the data.\n");
743743

744744
inflateEnd(&request->stream);
745-
SHA1_Final(request->real_sha1, &request->c);
745+
git_SHA1_Final(request->real_sha1, &request->c);
746746
if (request->zret != Z_STREAM_END) {
747747
unlink(request->tmpfile);
748748
} else if (hashcmp(request->obj->sha1, request->real_sha1)) {

0 commit comments

Comments
 (0)