Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AArch64] .note.gnu.property always generated for object file without code #45825

Closed
kees opened this issue Jun 27, 2020 · 7 comments
Closed
Assignees
Labels
bugzilla Issues migrated from bugzilla clang Clang issues not falling into any other category

Comments

@kees
Copy link
Contributor

kees commented Jun 27, 2020

Bugzilla Link 46480
Resolution FIXED
Resolved on Sep 28, 2020 09:39
Version trunk
OS Linux
Blocks #4440
CC @DanielKristofKiss,@MaskRay,@kbeyls,@momchil-velikov,@nickdesaulniers,@zygoloid
Fixed by commit(s) a48f607

Extended Description

The .note.gnu.property is generated even when -mbranch-protection=none is used, on a source file that only has data (no code).

$ cat foo.c
int global = 5;
$ clang --target=aarch64-linux-gnu -c -o foo.o foo.c
$ readelf -n foo.o

Displaying notes found in: .note.gnu.property
Owner Data size Description
GNU 0x00000010 NT_GNU_PROPERTY_TYPE_0
Properties: AArch64 feature: BTI, PAC
$ clang --target=aarch64-linux-gnu -mbranch-protection=none -c -o foo.o foo.c
$ readelf -n foo.o

Displaying notes found in: .note.gnu.property
Owner Data size Description
GNU 0x00000010 NT_GNU_PROPERTY_TYPE_0
Properties: AArch64 feature: BTI, PAC
$ aarch64-linux-gnu-gcc -c -o foo.o foo.c
$ readelf -n foo.o
$ aarch64-linux-gnu-gcc -mbranch-protection=bti -c -o foo.o foo.c
$ readelf -n foo.o

Displaying notes found in: .note.gnu.property
Owner Data size Description
GNU 0x00000010 NT_GNU_PROPERTY_TYPE_0
Properties: AArch64 feature: BTI

$ cat bar.c
int code(void) { return 5; }
$ clang --target=aarch64-linux-gnu -c -o bar.o bar.c
$ readelf -n bar.o
$ clang --target=aarch64-linux-gnu -mbranch-protection=bti -c -o bar.o bar.c
$ readelf -n bar.o

Displaying notes found in: .note.gnu.property
Owner Data size Description
GNU 0x00000010 NT_GNU_PROPERTY_TYPE_0
Properties: AArch64 feature: BTI

@kees
Copy link
Contributor Author

kees commented Jun 27, 2020

assigned to @DanielKristofKiss

@DanielKristofKiss
Copy link
Member

This patch will fix this: https://reviews.llvm.org/D80791

@momchil-velikov
Copy link
Collaborator

I don't think this is a bug. From the Arm ELF64 ABI(2020Q2) we have first from
section 6.2

"GNU_PROPERTY_AARCH64_FEATURE_1_AND describes a set of processor features with
which an ELF object or executable image is compatible, but does not require
in order to execute correctly."

Certainly an object that contains no code is compatible with the PAC and BTI
features, without requiring them.

"Static linkers processing ELF relocatable objects must set the feature bit
in the output object or image only if all the input objects have the
corresponding feature bit set."

If the compiler didn't set those feature bits in an object file, which did not
contain code, then the linker must clear the feature bit from the final image,
which is clearly unwarranted, as the said object is fully compatible.

@momchil-velikov
Copy link
Collaborator

Also -mbranch-protection=none does not have the semantics of preventing the object to participate in a PAC/BTI enabled image. Passing the value of none
is equivalent to not passing the option at all.

@llvmbot
Copy link
Collaborator

llvmbot commented Jul 15, 2020

This behaviour is in spec but from a practical deployment point of view I don't think it's good - at present we have the latest release of at least Debian (which is pretty widely used, especially on arm64) shipping a version of binutils that complains loudly any time it sees one of the notes but there's no way to stop the compiler emitting them. The fact that Debian is affected is especially unfortunate since it's quite commonly used as a basis for Docker containers used in CI systems.

The kernel is passing -mbranch-protection=none for separate reasons, it's doing it because the compiler might not default to none (eg, a distribution trying to get everything built with branch protection) but this can cause issues if the kernel is not expecting it (eg, if we have userspace but not kernel mode PAC any PAC instructions in the kernel will crash).

@momchil-velikov
Copy link
Collaborator

This behaviour is in spec but from a practical deployment point of view I
don't think it's good - at present we have the latest release of at least
Debian (which is pretty widely used, especially on arm64) shipping a version
of binutils that complains loudly any time it sees one of the notes but
there's no way to stop the compiler emitting them.

Equivalently, there's no way of stopping the linker from emitting the warnings, I presume.

I absolutely agree there is a problem that we need to solve, but so far I'm not convinced that the problem is in the specification or the compiler. It's in the linker.

@llvmbot
Copy link
Collaborator

llvmbot commented Jul 15, 2020

Equivalently, there's no way of stopping the linker from emitting the warnings, > I presume.

Not that we're aware of.

I absolutely agree there is a problem that we need to solve, but so far I'm not > convinced that the problem is in the specification or the compiler. It's in the > linker.

Or the packaging of the compiler - if we're saying an updated linker is required then distributions of the compiler such as provided by llvm.org really ought to be ensuring that a suitable linker is available. Unfortunately lld still seems to have issues building the kernel and isn't used by default:

$ clang-11 -target aarch64-linux-gnu /tmp/foo.c /tmp/bar.c
/usr/bin/aarch64-linux-gnu-ld: warning: /tmp/bar-20bf33.o: unsupported GNU_PROPERTY_TYPE (5) type: 0xc0000000

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla clang Clang issues not falling into any other category
Projects
None yet
Development

No branches or pull requests

4 participants