diff mbox series

disabling sha1dc unaligned access, was Re: One failed self test on Fedora 29

Message ID 20190311033755.GB7087@sigill.intra.peff.net (mailing list archive)
State New, archived
Headers show
Series disabling sha1dc unaligned access, was Re: One failed self test on Fedora 29 | expand

Commit Message

Jeff King March 11, 2019, 3:37 a.m. UTC
On Mon, Mar 11, 2019 at 11:00:25AM +0900, Junio C Hamano wrote:

> Jeffrey Walton <noloader@gmail.com> writes:
> 
> > I think this is the patch for sha1dc/sha1.c . It stops using unaligned
> > accesses by default, but still honors SHA1DC_FORCE_UNALIGNED_ACCESS
> > for those who want it. Folks who want the undefined behavior have to
> > do something special.
> 
> Hmph, I somehow thought that folks who want to stick to the
> standard printed on paper penalizing what practicaly works well in
> the real world would be the one doing extra things.

Unfortunately, I don't think sha1dc currently supports #defines in that
direction. The only logic is "if we are on intel, do unaligned loads"
and "even if we are not on intel, do it anyway". There is no "even if we
are on intel, do not do unaligned loads".

I think you'd need something like this:


but of course we cannot touch sha1dc/*, because we might actually be
using the submodule copy instead. And AFAIK there is no good way to
modify the submodule-provided content as part of the build. Why do we
even have the submodule again? ;P

I guess the same would be true for DC_SHA1_EXTERNAL, too, though.

So anyway, I think this needs a patch to the upstream sha1dc project.

-Peff

Comments

Jeffrey Walton March 11, 2019, 10:40 a.m. UTC | #1
On Sun, Mar 10, 2019 at 11:37 PM Jeff King <peff@peff.net> wrote:
>
> On Mon, Mar 11, 2019 at 11:00:25AM +0900, Junio C Hamano wrote:
>
> > Jeffrey Walton <noloader@gmail.com> writes:
> >
> > > I think this is the patch for sha1dc/sha1.c . It stops using unaligned
> > > accesses by default, but still honors SHA1DC_FORCE_UNALIGNED_ACCESS
> > > for those who want it. Folks who want the undefined behavior have to
> > > do something special.
> >
> > Hmph, I somehow thought that folks who want to stick to the
> > standard printed on paper penalizing what practicaly works well in
> > the real world would be the one doing extra things.
>
> Unfortunately, I don't think sha1dc currently supports #defines in that
> direction. The only logic is "if we are on intel, do unaligned loads"
> and "even if we are not on intel, do it anyway". There is no "even if we
> are on intel, do not do unaligned loads".
>
> I think you'd need something like this:
>
> diff --git a/Makefile b/Makefile
> index 148668368b..705c54dcd8 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -1194,6 +1194,7 @@ BASIC_CFLAGS += -fsanitize=$(SANITIZE) -fno-sanitize-recover=$(SANITIZE)
>  BASIC_CFLAGS += -fno-omit-frame-pointer
>  ifneq ($(filter undefined,$(SANITIZERS)),)
>  BASIC_CFLAGS += -DNO_UNALIGNED_LOADS
> +BASIC_CFLAGS += -DSHA1DC_DISALLOW_UNALIGNED_ACCESS
>  endif
>  ifneq ($(filter leak,$(SANITIZERS)),)
>  BASIC_CFLAGS += -DSUPPRESS_ANNOTATED_LEAKS
> diff --git a/sha1dc/sha1.c b/sha1dc/sha1.c
> index df0630bc6d..0bdf80d778 100644
> --- a/sha1dc/sha1.c
> +++ b/sha1dc/sha1.c
> @@ -124,9 +124,11 @@
>  #endif
>  /*ENDIANNESS SELECTION*/
>
> +#ifndef SHA1DC_DISALLOW_UNALIGNED_ACCESS
>  #if defined(SHA1DC_FORCE_UNALIGNED_ACCESS) || defined(SHA1DC_ON_INTEL_LIKE_PROCESSOR)
>  #define SHA1DC_ALLOW_UNALIGNED_ACCESS
>  #endif /*UNALIGNMENT DETECTION*/
> +#endif
>
>
>  #define rotate_right(x,n) (((x)>>(n))|((x)<<(32-(n))))
>
> but of course we cannot touch sha1dc/*, because we might actually be
> using the submodule copy instead. And AFAIK there is no good way to
> modify the submodule-provided content as part of the build. Why do we
> even have the submodule again? ;P
>
> I guess the same would be true for DC_SHA1_EXTERNAL, too, though.
>
> So anyway, I think this needs a patch to the upstream sha1dc project.

https://github.com/cr-marcstevens/sha1collisiondetection/issues/47

Jeff
Duy Nguyen March 11, 2019, 11:58 a.m. UTC | #2
On Mon, Mar 11, 2019 at 10:48 AM Jeff King <peff@peff.net> wrote:
> And AFAIK there is no good way to
> modify the submodule-provided content as part of the build. Why do we
> even have the submodule again? ;P

Because of dogfooding of course. This is an interesting use case
though. I wonder if people often want to "patch" submodules like this
(and what we could do if that's the case)
Thomas Braun March 11, 2019, 6:15 p.m. UTC | #3
Am 11.03.2019 um 12:58 schrieb Duy Nguyen:
> On Mon, Mar 11, 2019 at 10:48 AM Jeff King <peff@peff.net> wrote:
>> And AFAIK there is no good way to
>> modify the submodule-provided content as part of the build. Why do we
>> even have the submodule again? ;P
> 
> Because of dogfooding of course. This is an interesting use case
> though. I wonder if people often want to "patch" submodules like this
> (and what we could do if that's the case)

I usually do the following:

- Fork the sub-project
- Add a branch with my proposed patches
- Update the URL and the commit of the submodule in the super-project

This of course requires all users to do

git submodule sync

which is a bit incovenient, but works.
Jeff King March 11, 2019, 6:19 p.m. UTC | #4
On Mon, Mar 11, 2019 at 06:40:21AM -0400, Jeffrey Walton wrote:

> > So anyway, I think this needs a patch to the upstream sha1dc project.
> 
> https://github.com/cr-marcstevens/sha1collisiondetection/issues/47

Thanks, it looks like the turnaround on that may be pretty quick. Once
it's merged there, we'll need a local patch to bump the gitlink sha1 and
tweak the Makefile.

-Peff
Jeff King March 11, 2019, 6:23 p.m. UTC | #5
On Mon, Mar 11, 2019 at 07:15:12PM +0100, Thomas Braun wrote:

> Am 11.03.2019 um 12:58 schrieb Duy Nguyen:
> > On Mon, Mar 11, 2019 at 10:48 AM Jeff King <peff@peff.net> wrote:
> >> And AFAIK there is no good way to
> >> modify the submodule-provided content as part of the build. Why do we
> >> even have the submodule again? ;P
> > 
> > Because of dogfooding of course. This is an interesting use case
> > though. I wonder if people often want to "patch" submodules like this
> > (and what we could do if that's the case)
> 
> I usually do the following:
> 
> - Fork the sub-project
> - Add a branch with my proposed patches
> - Update the URL and the commit of the submodule in the super-project
> 
> This of course requires all users to do
> 
> git submodule sync
> 
> which is a bit incovenient, but works.

The problem to me is not that the steps that a developer has to do, but
rather that we are dependent on the upstream project to make a simple
fix (which they may not agree to do, or may take a long time to do).

Whereas if we import the content into our repo as a subtree, we are free
to hack it up as we see fit, and then occasionally pull from upstream
and reconcile the changes. Changing upstream isn't advisable in the
general case, but I think makes a lot of sense for small changes
(especially if you have the discipline to actually get the same or
similar change pushed upstream).

In this particular case, though, the sha1dc project is pretty
responsive, so I don't think it's going to be a big deal. It just seems
like an anti-pattern in general.

-Peff
Junio C Hamano March 12, 2019, 7:27 a.m. UTC | #6
Jeff King <peff@peff.net> writes:

> The problem to me is not that the steps that a developer has to do, but
> rather that we are dependent on the upstream project to make a simple
> fix (which they may not agree to do, or may take a long time to do).

Yeah.  In practice, I think the recommended way to work for a
depending project like us is to keep a fork in a separate repository
we control of the submodule project, and allow our fork to be
slightly ahead of the upstream while feeding our change to them.
Ævar Arnfjörð Bjarmason March 12, 2019, 8:53 a.m. UTC | #7
On Mon, Mar 11 2019, Jeff King wrote:

> On Mon, Mar 11, 2019 at 07:15:12PM +0100, Thomas Braun wrote:
>
>> Am 11.03.2019 um 12:58 schrieb Duy Nguyen:
>> > On Mon, Mar 11, 2019 at 10:48 AM Jeff King <peff@peff.net> wrote:
>> >> And AFAIK there is no good way to
>> >> modify the submodule-provided content as part of the build. Why do we
>> >> even have the submodule again? ;P
>> >
>> > Because of dogfooding of course. This is an interesting use case
>> > though. I wonder if people often want to "patch" submodules like this
>> > (and what we could do if that's the case)
>>
>> I usually do the following:
>>
>> - Fork the sub-project
>> - Add a branch with my proposed patches
>> - Update the URL and the commit of the submodule in the super-project
>>
>> This of course requires all users to do
>>
>> git submodule sync
>>
>> which is a bit incovenient, but works.
>
> The problem to me is not that the steps that a developer has to do, but
> rather that we are dependent on the upstream project to make a simple
> fix (which they may not agree to do, or may take a long time to do).
>
> Whereas if we import the content into our repo as a subtree, we are free
> to hack it up as we see fit, and then occasionally pull from upstream
> and reconcile the changes. Changing upstream isn't advisable in the
> general case, but I think makes a lot of sense for small changes
> (especially if you have the discipline to actually get the same or
> similar change pushed upstream).
>
> In this particular case, though, the sha1dc project is pretty
> responsive, so I don't think it's going to be a big deal. It just seems
> like an anti-pattern in general.

There's a at least a couple of aspects to this.

One is whether we should have the submodule in
sha1collisiondetection/. I agree that's probably a bad idea now
per-se. Honestly I wasn't expecting the answer when I submitted the
final patch to switch to it fully to be to the effect of submodules
being too immature for the git project itself to use. So now we're
effectively mid-series, and should maybe just back out.

But the other is the developer social engineering question of how we
strike the right trade-off when we import upstream code.

I fully agree with what you've said in theory, but if we look at what's
happened in practice we as a project are demonstrably not disciplined
enough to manage upstream code like this without overtly perma-forking
it.

E.g. I gave up on updating compat/regex some time ago because of the
various cross-tree patches that had ended up modifying it. Now we can't
just upstream a new engine anymore.

Someone needs to first go through those various modifications, upstream
them one-by-one or prove they're not needed anymore (and many are
portability / obscure compiler fixes, so that's hard...). The
compat/regex isn't unique here, e.g. compat/poll/ is another example of
this.

As far as I can tell none of the people changing that code went through
the process of submitting a parallel upstream fix or seeing if the issue
was fixed upstream and we could just update the code we were carrying,
and of course that gets progressively harder for any one contributor as
our divergence grows.

So even though the theory of the sha1collisiondetection/ submodule +
sha1dc/ code fork is silly, perhaps we've stumbled upon some way where
we at least file an upstream bug for issues we find and fix. As
demonstrated by other such changes that's already leaps and bounds ahead
of what we're usually doing.
Jeff King March 12, 2019, 10:51 a.m. UTC | #8
On Tue, Mar 12, 2019 at 04:27:57PM +0900, Junio C Hamano wrote:

> Jeff King <peff@peff.net> writes:
> 
> > The problem to me is not that the steps that a developer has to do, but
> > rather that we are dependent on the upstream project to make a simple
> > fix (which they may not agree to do, or may take a long time to do).
> 
> Yeah.  In practice, I think the recommended way to work for a
> depending project like us is to keep a fork in a separate repository
> we control of the submodule project, and allow our fork to be
> slightly ahead of the upstream while feeding our change to them.

Reading Thomas's email again, that might actually have been what he was
recommending. If so, sorry for the confusion. And I agree that's a valid
solution.

That said, I do wonder at some point if there's a huge value in using a
submodule at that point. I think there is if the dependent project is
large (and if it's optional, and some people might not need it). But in
this case, it is not a big deal to just carry the sha1dc code in-tree.

-Peff
Jeff King March 12, 2019, 11:05 a.m. UTC | #9
On Tue, Mar 12, 2019 at 09:53:41AM +0100, Ævar Arnfjörð Bjarmason wrote:

> There's a at least a couple of aspects to this.
> 
> One is whether we should have the submodule in
> sha1collisiondetection/. I agree that's probably a bad idea now
> per-se. Honestly I wasn't expecting the answer when I submitted the
> final patch to switch to it fully to be to the effect of submodules
> being too immature for the git project itself to use. So now we're
> effectively mid-series, and should maybe just back out.

I think it's especially funky because we have three different ways of
getting sha1dc (in-tree, submodule, or against an external library). And
I almost blindly submitted a patch making the in-tree version work
(since that's what's used by default, and what I use) which could have
totally broken things for the other use cases without anybody realizing
until the change trickled down to somebody who uses those flags.

(Technically in this case it wouldn't actually have _broken_ them, but
just not helped them, so they'd be no worse off. But hopefully you get
the point).

Speaking of external libraries, in some ways the issue I raised is no
different than it is for any external library, where we're at the mercy
of whatever version is on the system. The big dependency for us is
usually libcurl, and we do have to sometimes work around old versions
there.

But I do think there's one thing that make the sha1dc submodule approach
more painful is that we don't control the content of the code, but we
_do_ build it ourselves with our usual compiler flags. So we're weirdly
intimate with it (and in fact, an external library would not have the
problem being discussed here, since it would have been built separately
without UBSan).

> I fully agree with what you've said in theory, but if we look at what's
> happened in practice we as a project are demonstrably not disciplined
> enough to manage upstream code like this without overtly perma-forking
> it.

I'm not sure I agree completely. Most of the things we've imported are
small enough that we're reasonably happy to accept them as a snapshot in
time and take ownership. I.e., I do not recall a lot of instances of
fixing bugs in compat/regex or compat/poll that we could have gotten
more easily by merging from upstream. But I admit I don't actually pay
much attention to those areas, so I might be completely off-base.

The one place I really _would_ have liked to remain compatible with
upstream is xdiff. And we were traditionally pretty hesitant to clean
things up there for fear of diverging. But in practice, upstream there
has been stagnant, and we've done most of the bug fixes and improvements
to it (in-tree).

> As far as I can tell none of the people changing that code went through
> the process of submitting a parallel upstream fix or seeing if the issue
> was fixed upstream and we could just update the code we were carrying,
> and of course that gets progressively harder for any one contributor as
> our divergence grows.

To be clear, I do sympathize with the notion that not pulling things
in-tree keeps our relationship with upstream more disciplined, and that
has value. I'm just not altogether clear how much it's really hurt us
overall to be undisciplined.

-Peff
Ævar Arnfjörð Bjarmason March 12, 2019, 12:09 p.m. UTC | #10
On Tue, Mar 12 2019, Jeff King wrote:

> On Tue, Mar 12, 2019 at 09:53:41AM +0100, Ævar Arnfjörð Bjarmason wrote:
>
>> There's a at least a couple of aspects to this.
>>
>> One is whether we should have the submodule in
>> sha1collisiondetection/. I agree that's probably a bad idea now
>> per-se. Honestly I wasn't expecting the answer when I submitted the
>> final patch to switch to it fully to be to the effect of submodules
>> being too immature for the git project itself to use. So now we're
>> effectively mid-series, and should maybe just back out.
>
> I think it's especially funky because we have three different ways of
> getting sha1dc (in-tree, submodule, or against an external library). And
> I almost blindly submitted a patch making the in-tree version work
> (since that's what's used by default, and what I use) which could have
> totally broken things for the other use cases without anybody realizing
> until the change trickled down to somebody who uses those flags.
>
> (Technically in this case it wouldn't actually have _broken_ them, but
> just not helped them, so they'd be no worse off. But hopefully you get
> the point).
>
> Speaking of external libraries, in some ways the issue I raised is no
> different than it is for any external library, where we're at the mercy
> of whatever version is on the system. The big dependency for us is
> usually libcurl, and we do have to sometimes work around old versions
> there.
>
> But I do think there's one thing that make the sha1dc submodule approach
> more painful is that we don't control the content of the code, but we
> _do_ build it ourselves with our usual compiler flags. So we're weirdly
> intimate with it (and in fact, an external library would not have the
> problem being discussed here, since it would have been built separately
> without UBSan).
>
>> I fully agree with what you've said in theory, but if we look at what's
>> happened in practice we as a project are demonstrably not disciplined
>> enough to manage upstream code like this without overtly perma-forking
>> it.
>
> I'm not sure I agree completely. Most of the things we've imported are
> small enough that we're reasonably happy to accept them as a snapshot in
> time and take ownership. I.e., I do not recall a lot of instances of
> fixing bugs in compat/regex or compat/poll that we could have gotten
> more easily by merging from upstream. But I admit I don't actually pay
> much attention to those areas, so I might be completely off-base.
>
> The one place I really _would_ have liked to remain compatible with
> upstream is xdiff. And we were traditionally pretty hesitant to clean
> things up there for fear of diverging. But in practice, upstream there
> has been stagnant, and we've done most of the bug fixes and improvements
> to it (in-tree).
>
>> As far as I can tell none of the people changing that code went through
>> the process of submitting a parallel upstream fix or seeing if the issue
>> was fixed upstream and we could just update the code we were carrying,
>> and of course that gets progressively harder for any one contributor as
>> our divergence grows.
>
> To be clear, I do sympathize with the notion that not pulling things
> in-tree keeps our relationship with upstream more disciplined, and that
> has value. I'm just not altogether clear how much it's really hurt us
> overall to be undisciplined.

I agree that say the compat/regex divergence hasn't hurt us much if at
all. Just that we have a few conflicting desires:

 A. Make sure you can "make" git by default without pulling down a bunch
    of libraries, especially if they're not ubiquitous. Thus shipping
    the likes of sha1dc.

 B. Being able to hotfix those libraries.

 C. Upstreaming those hotfixes when they happen.

 D. Updating the library we pulled in due to "A" from upstream.

In practice because we've wanted "A" we've felt the need to do "B", but
then also not "C" without ever having the discussion that skipping that
part was a good idea, and as a result "D" is hard.

Do we urgently need "D"? No. I'm just pointing out that in addition to
optimzing for "B" being easy we should also weigh being good free
software citizens and coordinate fixes with upstream, which also makes a
future "D" easier.

Also, while I don't know of any bugs in compat/regex. I think it's a bit
concerning that we're carrying 2010-era code for something like the
regex engine that we expose e.g. over gitweb.
Jeff King March 12, 2019, 9:01 p.m. UTC | #11
On Tue, Mar 12, 2019 at 01:09:42PM +0100, Ævar Arnfjörð Bjarmason wrote:

> > To be clear, I do sympathize with the notion that not pulling things
> > in-tree keeps our relationship with upstream more disciplined, and that
> > has value. I'm just not altogether clear how much it's really hurt us
> > overall to be undisciplined.
> 
> I agree that say the compat/regex divergence hasn't hurt us much if at
> all. Just that we have a few conflicting desires:
> 
>  A. Make sure you can "make" git by default without pulling down a bunch
>     of libraries, especially if they're not ubiquitous. Thus shipping
>     the likes of sha1dc.
> 
>  B. Being able to hotfix those libraries.
> 
>  C. Upstreaming those hotfixes when they happen.
> 
>  D. Updating the library we pulled in due to "A" from upstream.
> 
> In practice because we've wanted "A" we've felt the need to do "B", but
> then also not "C" without ever having the discussion that skipping that
> part was a good idea, and as a result "D" is hard.
> 
> Do we urgently need "D"? No. I'm just pointing out that in addition to
> optimzing for "B" being easy we should also weigh being good free
> software citizens and coordinate fixes with upstream, which also makes a
> future "D" easier.

Yeah, I think your mental model there makes some sense.

> Also, while I don't know of any bugs in compat/regex. I think it's a bit
> concerning that we're carrying 2010-era code for something like the
> regex engine that we expose e.g. over gitweb.

TBH, I think it's probably a bad idea to open any version of that code
to untrusted people, because it's easy to write a DoS regex against it.
There are libraries (like re2) that would be a better fit (I seem to
recall that there may be some DFA-only support in pcre, too, but I
haven't looked at it in a long time; if there is, it might be a sane
gitweb feature to only expose that engine).

-Peff
Thomas Braun March 13, 2019, 11:47 a.m. UTC | #12
Am 12.03.2019 um 11:51 schrieb Jeff King:
> On Tue, Mar 12, 2019 at 04:27:57PM +0900, Junio C Hamano wrote:
> 
>> Jeff King <peff@peff.net> writes:
>>
>>> The problem to me is not that the steps that a developer has to do, but
>>> rather that we are dependent on the upstream project to make a simple
>>> fix (which they may not agree to do, or may take a long time to do).
>>
>> Yeah.  In practice, I think the recommended way to work for a
>> depending project like us is to keep a fork in a separate repository
>> we control of the submodule project, and allow our fork to be
>> slightly ahead of the upstream while feeding our change to them.
> 
> Reading Thomas's email again, that might actually have been what he was
> recommending. If so, sorry for the confusion. And I agree that's a valid
> solution.

Yes that is what I tried to explain. Looks like it was lost in translation.

> That said, I do wonder at some point if there's a huge value in using a
> submodule at that point. I think there is if the dependent project is
> large (and if it's optional, and some people might not need it). But in
> this case, it is not a big deal to just carry the sha1dc code in-tree.

A big win with submodules is that you have separate histories and can,
quite easily, update to newer versions without manual copying.

One grievance with submodules is the URL switching if you need to go
with a forked repo for some time and then back to the original.
Is it possible to have multiple remotes for a submodule?

Something like:

[submodule "libfoo"]
	path = include/foo
	url1 = git://foo.com/upstream/lib.git
	url2 = git://foo.com/myFork/lib.git

With that the error prone git submodule sync step is not required anymore.

submodule.alternateLocation looks like it is going into the right direction.
Jeff King March 13, 2019, 3:39 p.m. UTC | #13
On Wed, Mar 13, 2019 at 12:47:51PM +0100, Thomas Braun wrote:

> > Reading Thomas's email again, that might actually have been what he was
> > recommending. If so, sorry for the confusion. And I agree that's a valid
> > solution.
> 
> Yes that is what I tried to explain. Looks like it was lost in translation.

I think the problem was on the reading end. :)

> > That said, I do wonder at some point if there's a huge value in using a
> > submodule at that point. I think there is if the dependent project is
> > large (and if it's optional, and some people might not need it). But in
> > this case, it is not a big deal to just carry the sha1dc code in-tree.
> 
> A big win with submodules is that you have separate histories and can,
> quite easily, update to newer versions without manual copying.

True. We'd generally be picking up snapshots in our in-tree sha1dc/, so
bisecting on it is not as fine-grained. We _could_ pull in the full
history using something like git-subtree, but that comes with its own
complications.

> One grievance with submodules is the URL switching if you need to go
> with a forked repo for some time and then back to the original.
> Is it possible to have multiple remotes for a submodule?
> 
> Something like:
> 
> [submodule "libfoo"]
> 	path = include/foo
> 	url1 = git://foo.com/upstream/lib.git
> 	url2 = git://foo.com/myFork/lib.git
> 
> With that the error prone git submodule sync step is not required anymore.

I assume you'd fetch from _all_ of them during a fetch, and assume that
one of them will get you the objects you need (or I guess if you are
looking for a specific object, you'd try them one at a time until you
get the object).

That makes sense, though it might be kind of annoying when fetching is
expensive (especially if it involves manually authenticating).

> submodule.alternateLocation looks like it is going into the right direction.

I think that's mostly about pointing back to the superproject for local
storage. Though I think there's a pretty reasonable solution to the
problem we're discussing there: git.git could carry a "sha1dc" branch
that points to our modified submodule history. So it's "in-tree" in the
sense that that it is in our repo, and under our full control, but still
managed like a submodule.

And we'd probably not even duplicate a lot of storage in the actual
clone of the upstream project, because it would be pointing to us as an
alternate.

-Peff
Ævar Arnfjörð Bjarmason March 13, 2019, 4 p.m. UTC | #14
On Wed, Mar 13 2019, Jeff King wrote:

> On Wed, Mar 13, 2019 at 12:47:51PM +0100, Thomas Braun wrote:
>
>> > Reading Thomas's email again, that might actually have been what he was
>> > recommending. If so, sorry for the confusion. And I agree that's a valid
>> > solution.
>>
>> Yes that is what I tried to explain. Looks like it was lost in translation.
>
> I think the problem was on the reading end. :)
>
>> > That said, I do wonder at some point if there's a huge value in using a
>> > submodule at that point. I think there is if the dependent project is
>> > large (and if it's optional, and some people might not need it). But in
>> > this case, it is not a big deal to just carry the sha1dc code in-tree.
>>
>> A big win with submodules is that you have separate histories and can,
>> quite easily, update to newer versions without manual copying.
>
> True. We'd generally be picking up snapshots in our in-tree sha1dc/, so
> bisecting on it is not as fine-grained. We _could_ pull in the full
> history using something like git-subtree, but that comes with its own
> complications.
>
>> One grievance with submodules is the URL switching if you need to go
>> with a forked repo for some time and then back to the original.
>> Is it possible to have multiple remotes for a submodule?
>>
>> Something like:
>>
>> [submodule "libfoo"]
>> 	path = include/foo
>> 	url1 = git://foo.com/upstream/lib.git
>> 	url2 = git://foo.com/myFork/lib.git
>>
>> With that the error prone git submodule sync step is not required anymore.
>
> I assume you'd fetch from _all_ of them during a fetch, and assume that
> one of them will get you the objects you need (or I guess if you are
> looking for a specific object, you'd try them one at a time until you
> get the object).
>
> That makes sense, though it might be kind of annoying when fetching is
> expensive (especially if it involves manually authenticating).
>
>> submodule.alternateLocation looks like it is going into the right direction.
>
> I think that's mostly about pointing back to the superproject for local
> storage. Though I think there's a pretty reasonable solution to the
> problem we're discussing there: git.git could carry a "sha1dc" branch
> that points to our modified submodule history. So it's "in-tree" in the
> sense that that it is in our repo, and under our full control, but still
> managed like a submodule.
>
> And we'd probably not even duplicate a lot of storage in the actual
> clone of the upstream project, because it would be pointing to us as an
> alternate.

Now if only we could think of some way to give the people best
positioned to fix some of these UI issues for git users everywhere the
incentive to do so[1] :)

1. https://public-inbox.org/git/20171208223001.556-5-avarab@gmail.com/
diff mbox series

Patch

diff --git a/Makefile b/Makefile
index 148668368b..705c54dcd8 100644
--- a/Makefile
+++ b/Makefile
@@ -1194,6 +1194,7 @@  BASIC_CFLAGS += -fsanitize=$(SANITIZE) -fno-sanitize-recover=$(SANITIZE)
 BASIC_CFLAGS += -fno-omit-frame-pointer
 ifneq ($(filter undefined,$(SANITIZERS)),)
 BASIC_CFLAGS += -DNO_UNALIGNED_LOADS
+BASIC_CFLAGS += -DSHA1DC_DISALLOW_UNALIGNED_ACCESS
 endif
 ifneq ($(filter leak,$(SANITIZERS)),)
 BASIC_CFLAGS += -DSUPPRESS_ANNOTATED_LEAKS
diff --git a/sha1dc/sha1.c b/sha1dc/sha1.c
index df0630bc6d..0bdf80d778 100644
--- a/sha1dc/sha1.c
+++ b/sha1dc/sha1.c
@@ -124,9 +124,11 @@ 
 #endif
 /*ENDIANNESS SELECTION*/
 
+#ifndef SHA1DC_DISALLOW_UNALIGNED_ACCESS
 #if defined(SHA1DC_FORCE_UNALIGNED_ACCESS) || defined(SHA1DC_ON_INTEL_LIKE_PROCESSOR)
 #define SHA1DC_ALLOW_UNALIGNED_ACCESS
 #endif /*UNALIGNMENT DETECTION*/
+#endif
 
 
 #define rotate_right(x,n) (((x)>>(n))|((x)<<(32-(n))))