[cfe-dev] Should hard links be distinct for #pragma once purposes?

Shoaib Meenai via cfe-dev cfe-dev at lists.llvm.org
Mon Jun 28 10:44:34 PDT 2021


We have a remote build system that uses content-addressed storage, in which all files with the same content are hard linked. I noticed that our output object files differed when they were compiled locally vs. remotely, and it turns out that #pragma once considers hard links to be identical, regardless of their path. Our local builds don’t have the hard linking but our remote builds do, so the include tree is different between local and remote builds (because of the #pragma once behavior difference), which causes debug info to differ.

Is this behavior desirable? You can construct a convoluted example that works when you copy a file and fails when you hard link it:

$ cat evil.h
#pragma once
#ifdef EVIL_ONE
#define EVIL_TWO
#endif
#define EVIL_ONE

$ cp evil.h evil2.h

$ cat evil.c
#include "evil.h"
#include "evil2.h"
#ifndef EVIL_TWO
#error Not evil enough
#endif

$ clang -c evil.c
# compiles successfully

$ rm evil2.h
$ ln evil.h evil2.h
$ clang -c evil.c
evil.c:4:2: error: Not evil enough
#error Not evil enough
^
1 error generated.

gcc behaves the same as clang in this case, for what it’s worth. https://bugs.llvm.org/show_bug.cgi?id=26579 looks related, although my question is specifically about #pragma once’s intended behavior.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20210628/08bca970/attachment-0001.html>


More information about the cfe-dev mailing list