bugmake - Bugs: bug #60960, Fix/report race problem if having...

 
 

bug #60960: Fix/report race problem if having multiple "alias" for the same target

Submitted by:  None
Submitted on:  Thu 22 Jul 2021 01:49:14 PM UTC
 
Severity:  3 - Normal Item Group:  Enhancement
Status:  None Privacy:  Public
Assigned to:  None Open/Closed:  Open
Component Version:  4.2.1 Operating System:  None
Fixed Release:  None Triage Status:  None
* Mandatory Fields

Add a New Comment (Rich Markup)
   

Comment Type & Canned Response:
       No canned response available

 

Thu 22 Jul 2021 07:10:04 PM UTC, comment #1: 

It's actually a very hard problem to know whether two paths are really the "same file" or not.  That's why make uses a simple textual comparison and leaves it at that (it does try one trivial simplification: it treats the targets "./foo" and "foo" as the same).

If we were to limit ourselves to traditional POSIX-style filesystems then we could use a combination of device ID and inode, which should be unique.  However, it's not clear all other filesystems have similar facilities so portability might be an issue.

Assuming we could come up with a portable way to uniquely identify that one file was reachable via different paths, then it would probably not be too bad to have make detect this situation at runtime, but only if it were actually going to build both targets in the same instance of make.  We could just remember the unique ID of all the targets we've already built and if we find a different target with the same unique ID as one we have remembered, we could write a warning or fail the build.  Then it would be up to users to fix their makefiles.

You wouldn't get any notification if you only built one of the "duplicate" paths and not the other in a given invocation of make.

I don't see any realistic way that make could magically coalesce two such targets into one and "fix up" this mistake on its own.

Also, I'm pretty sure having make fail if it detected this situation would be considered a violation of POSIX.

I will leave this enhancement request open for now, to think about.

Paul D. Smith <psmith>
Project Administrator
Thu 22 Jul 2021 01:49:14 PM UTC, original submission:  

Our team faced some race problems while building a project with Make.

Precise analysis shows that the problem was in fact, that Make doesn't care if we have different aliases for the same target.
For example:
```
.PHONY: all ../1/../main.o ../2/../main.o

all: ../1/../main.o ../2/../main.o

../1/../main.o:
ccache gcc -o $@ -c ../main.c

../2/../main.o:
ccache gcc -o $@ -c ../main.c
```

Here, we have 2 targets:
../1/../main.o
../2/../main.o

In fact, this is the same target/file (taking into account relative directories).
As a result if Make will create several threads (for each target) main.o file will be written concurrently (race condition).

Make doesn't operate in a wrong way.
Anyway, I think it would be great to have an additional checker in a Makefile which (at least) will notify the operator about the problem in a Makefile.

P.S. Makefile project, using which it is possible to reproduce the problem is attached to this ticket.

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #51680:  build_race.tar added by None (20KiB - application/octet-stream)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by psmith (Posted a comment)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

     

     

     

    Follows 1 latest change.

    Date Changed by Updated Field Previous Value => Replaced by
    2021-07-22 None Attached File- => Added build_race.tar, #51680

    Back to the top


    Powered by Savane 3.9