git: 46ce9acd6d15 - main - elfctl: add la52 for powerpc64
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 16 Nov 2026 12:34:40 UTC
The branch main has been updated by pkubaj:
URL: https://cgit.FreeBSD.org/src/commit/?id=46ce9acd6d157d3a63ca351a522d45a35ae83499
commit 46ce9acd6d157d3a63ca351a522d45a35ae83499
Author: Piotr Kubaj <pkubaj@FreeBSD.org>
AuthorDate: 2026-11-15 20:57:46 +0000
Commit: Piotr Kubaj <pkubaj@FreeBSD.org>
CommitDate: 2026-11-16 12:34:20 +0000
elfctl: add la52 for powerpc64
The 0x40 feature bit is la57 on amd64 and la52 on powerpc64. Tag each
feature with the machine it belongs to and only accept and show the
names that match the file's e_machine, so la57 is only known for amd64
files and la52 only for powerpc64 ones.
Reviewed by: kib
MFC after: 3 days
Differential Revision: https://reviews.freebsd.org/D61331
---
usr.bin/elfctl/elfctl.1 | 13 ++++++++++++-
usr.bin/elfctl/elfctl.c | 46 +++++++++++++++++++++++++++++++---------------
2 files changed, 43 insertions(+), 16 deletions(-)
diff --git a/usr.bin/elfctl/elfctl.1 b/usr.bin/elfctl/elfctl.1
index c9e168234554..1029b0c4bc24 100644
--- a/usr.bin/elfctl/elfctl.1
+++ b/usr.bin/elfctl/elfctl.1
@@ -24,7 +24,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd October 5, 2023
+.Dd November 15, 2026
.Dt ELFCTL 1
.Os
.Sh NAME
@@ -109,6 +109,17 @@ The
.Va vm.pmap.prefer_uva_la48
sysctl MIB defines the default user address space size for binaries
which do not set either of these flags.
+.Pp
+On powerpc64,
+.Va la52
+names the same note bit and requests the full 52-bit address space of the
+radix MMU instead of the default 48 bits;
+.Va la48
+and
+.Va vm.pmap.prefer_uva_la48
+work as on amd64.
+Only the name that belongs to the file's architecture is recognised and
+displayed for this bit.
.Sh SEE ALSO
.Xr mitigations 7
.Sh HISTORY
diff --git a/usr.bin/elfctl/elfctl.c b/usr.bin/elfctl/elfctl.c
index cacd30b44b2d..3b95e3de4791 100644
--- a/usr.bin/elfctl/elfctl.c
+++ b/usr.bin/elfctl/elfctl.c
@@ -48,29 +48,35 @@
#include <unistd.h>
#include "_elftc.h"
-static bool convert_to_feature_val(const char *, uint32_t *);
-static bool edit_file_features(Elf *, int, int, char *, bool);
+static bool convert_to_feature_val(const char *, uint32_t *, unsigned int);
+static bool edit_file_features(Elf *, int, int, char *, bool, unsigned int);
static bool get_file_features(Elf *, int, int, uint32_t *, uint64_t *, bool);
static void print_features(void);
-static bool print_file_features(Elf *, int, int, char *, bool);
+static bool print_file_features(Elf *, int, int, char *, bool, unsigned int);
static void usage(void) __dead2;
struct ControlFeatures {
const char *alias;
unsigned long value;
const char *desc;
+ unsigned int machine; /* EM_* the name belongs to, EM_NONE for all */
};
static struct ControlFeatures featurelist[] = {
- { "noaslr", NT_FREEBSD_FCTL_ASLR_DISABLE, "Disable ASLR" },
+ { "noaslr", NT_FREEBSD_FCTL_ASLR_DISABLE, "Disable ASLR", EM_NONE },
{ "noprotmax", NT_FREEBSD_FCTL_PROTMAX_DISABLE,
- "Disable implicit PROT_MAX" },
- { "nostackgap", NT_FREEBSD_FCTL_STKGAP_DISABLE, "Disable stack gap" },
- { "wxneeded", NT_FREEBSD_FCTL_WXNEEDED, "Requires W+X mappings" },
+ "Disable implicit PROT_MAX", EM_NONE },
+ { "nostackgap", NT_FREEBSD_FCTL_STKGAP_DISABLE, "Disable stack gap",
+ EM_NONE },
+ { "wxneeded", NT_FREEBSD_FCTL_WXNEEDED, "Requires W+X mappings",
+ EM_NONE },
{ "la48", NT_FREEBSD_FCTL_LA48,
- "amd64: Limit user virtual addresses to 48 bits" },
+ "amd64, powerpc64: Limit user virtual addresses to 48 bits", EM_NONE },
{ "la57", NT_FREEBSD_FCTL_LA57,
- "amd64: Allow the use of 57-bit virtual addresses when available" },
+ "amd64: Allow the use of 57-bit virtual addresses when available",
+ EM_X86_64 },
+ { "la52", NT_FREEBSD_FCTL_LA52,
+ "powerpc64: Allow the use of 52-bit virtual addresses", EM_PPC64 },
};
static struct option long_opts[] = {
@@ -180,12 +186,12 @@ main(int argc, char **argv)
if (!editfeatures) {
if (!print_file_features(elf, ehdr.e_phnum, fd,
- argv[0], endian_swap)) {
+ argv[0], endian_swap, ehdr.e_machine)) {
retval = 1;
goto fail;
}
} else if (!edit_file_features(elf, ehdr.e_phnum, fd,
- features, endian_swap)) {
+ features, endian_swap, ehdr.e_machine)) {
retval = 1;
goto fail;
}
@@ -222,7 +228,8 @@ usage(void)
}
static bool
-convert_to_feature_val(const char *feature_str, uint32_t *feature_val)
+convert_to_feature_val(const char *feature_str, uint32_t *feature_val,
+ unsigned int machine)
{
char *feature, *feature_tmp;
int i, len;
@@ -241,6 +248,10 @@ convert_to_feature_val(const char *feature_str, uint32_t *feature_val)
len = nitems(featurelist);
while ((feature = strsep(&feature_tmp, ",")) != NULL) {
for (i = 0; i < len; ++i) {
+ /* Names that belong to another architecture are unknown. */
+ if (featurelist[i].machine != EM_NONE &&
+ featurelist[i].machine != machine)
+ continue;
if (strcmp(featurelist[i].alias, feature) == 0) {
input |= featurelist[i].value;
break;
@@ -295,7 +306,8 @@ convert_to_feature_val(const char *feature_str, uint32_t *feature_val)
}
static bool
-edit_file_features(Elf *elf, int phcount, int fd, char *val, bool endian_swap)
+edit_file_features(Elf *elf, int phcount, int fd, char *val, bool endian_swap,
+ unsigned int machine)
{
uint32_t features, prev_features;
uint64_t off;
@@ -307,7 +319,7 @@ edit_file_features(Elf *elf, int phcount, int fd, char *val, bool endian_swap)
}
prev_features = features;
- if (!convert_to_feature_val(val, &features))
+ if (!convert_to_feature_val(val, &features, machine))
return (false);
/* Avoid touching file if no change. */
if (features == prev_features)
@@ -338,7 +350,7 @@ print_features(void)
static bool
print_file_features(Elf *elf, int phcount, int fd, char *filename,
- bool endian_swap)
+ bool endian_swap, unsigned int machine)
{
uint32_t features;
unsigned long i;
@@ -350,6 +362,10 @@ print_file_features(Elf *elf, int phcount, int fd, char *filename,
printf("File '%s' features:\n", filename);
for (i = 0; i < nitems(featurelist); ++i) {
+ /* The same bit has a different name on some architectures. */
+ if (featurelist[i].machine != EM_NONE &&
+ featurelist[i].machine != machine)
+ continue;
printf("%-16s'%s' is ", featurelist[i].alias,
featurelist[i].desc);