1
1
mirror of https://github.com/rui314/mold.git synced 2024-10-26 13:10:46 +03:00

Compare commits

...

5 Commits

Author SHA1 Message Date
Rui Ueyama
ec10452b67 Run tests on ppc64le machines 2023-07-30 13:12:44 +09:00
Rui Ueyama
ba3fd65bcc Refactor
Thanks to small string optimization, storing a short string to std::string
is usually more efficient than referring it from std::string_view.
2023-07-30 12:03:58 +09:00
Rui Ueyama
f816c45b88 Extend comments 2023-07-30 11:55:06 +09:00
Rui Ueyama
ca14cdf9b6 Do not create a PT_RISCV_ATTRIBUTES segment if .riscv.attributes is missing 2023-07-30 11:36:35 +09:00
Rui Ueyama
6d667fad45 Fix CI 2023-07-30 11:25:18 +09:00
5 changed files with 30 additions and 8 deletions

View File

@ -939,11 +939,13 @@ i64 riscv_resize_sections(Context<E> &ctx) {
// identified by name. Some extensions are of single-letter alphabet such
// as "m" or "q". Newer extension names start with "z" followed by one or
// more alphabets (i.e. "zicsr"). "s" and "x" prefixes are reserved
// for supervisor- level extensions and private extensions, respectively.
// for supervisor-level extensions and private extensions, respectively.
//
// Each extension consists of a name, a major version and a minor version.
// For example, "m2p0" indicates the "m" extension of version 2.0. "p" is
// just a separator.
// just a separator. Versions are often omitted in documents, but they are
// mandatory in .riscv.attributes. Likewise, abbreviations as "g" (which
// is short for "IMAFD") are not allowed in .riscv.attributes.
//
// Each RISC-V object file contains an ISA string enumerating extensions
// used by the object file. We need to merge input objects' ISA strings
@ -955,7 +957,7 @@ i64 riscv_resize_sections(Context<E> &ctx) {
// The following functions takes care of ISA strings.
struct Extn {
std::string_view name;
std::string name;
i64 major;
i64 minor;
};
@ -1082,12 +1084,12 @@ static std::vector<Extn> merge_extensions(std::span<Extn> x, std::span<Extn> y)
}
static std::string to_string(std::span<Extn> v) {
std::string str = std::string(v[0].name) + std::to_string(v[0].major) +
"p" + std::to_string(v[0].minor);
std::string str = v[0].name + std::to_string(v[0].major) + "p" +
std::to_string(v[0].minor);
for (i64 i = 1; i < v.size(); i++)
str += "_" + std::string(v[i].name) + std::to_string(v[i].major) +
"p" + std::to_string(v[i].minor);
str += "_" + v[i].name + std::to_string(v[i].major) + "p" +
std::to_string(v[i].minor);
return str;
}

View File

@ -355,7 +355,8 @@ static std::vector<ElfPhdr<E>> create_phdr(Context<E> &ctx) {
// Create a PT_RISCV_ATTRIBUTES
if constexpr (is_riscv<E>)
define(PT_RISCV_ATTRIBUTES, PF_R, 1, ctx.extra.riscv_attributes);
if (ctx.extra.riscv_attributes->shdr.sh_size)
define(PT_RISCV_ATTRIBUTES, PF_R, 1, ctx.extra.riscv_attributes);
// Create a PT_OPENBSD_RANDOMIZE
for (Chunk<E> *chunk : ctx.chunks)

View File

@ -11,6 +11,8 @@ function(add_target TRIPLE)
set(HOST arm)
elseif(${HOST} STREQUAL "ppc64")
set(HOST powerpc64)
elseif(${HOST} STREQUAL "ppc64le")
set(HOST powerpc64le)
endif()
if(${TRIPLE} MATCHES "${HOST}-.*")

View File

@ -5,6 +5,9 @@ cat <<EOF | $CC -march=rv64imafd_xfoo1p5 -o $t/a.o -c -xc -
void foo() {}
EOF
# The compiler might not create .riscv.attributes
readelf --sections $t/a.o | grep -Fq .riscv.attributes || skip
cat <<EOF | $CC -march=rv64imafd_xfoo2p0 -o $t/b.o -c -xc -
void bar() {}
EOF

14
test/elf/riscv64_attributes2.sh Executable file
View File

@ -0,0 +1,14 @@
#!/bin/bash
. $(dirname $0)/common.inc
cat <<EOF | $CC -o $t/a.o -c -xc -
void _start() {}
EOF
$STRIP --remove-section=.riscv.attributes $t/a.o
$CC -B. -nostdlib -o $t/exe $t/a.o
readelf -W --segments --sections $t/exe > $t/log
! grep -F .riscv.attributes $t/log || false
! grep -F RISCV_ATTR $t/log || false