summaryrefslogtreecommitdiff
path: root/libelftc
diff options
context:
space:
mode:
Diffstat (limited to 'libelftc')
-rw-r--r--libelftc/elftc_bfd_find_target.37
-rw-r--r--libelftc/elftc_reloc_type_str.c2
-rw-r--r--libelftc/elftc_string_table.c45
-rw-r--r--libelftc/elftc_string_table_create.312
-rw-r--r--libelftc/libelftc.h6
-rw-r--r--libelftc/libelftc_bfdtarget.c27
-rwxr-xr-xlibelftc/make-toolchain-version61
7 files changed, 97 insertions, 63 deletions
diff --git a/libelftc/elftc_bfd_find_target.3 b/libelftc/elftc_bfd_find_target.3
index 39d72b05341f..169c4723d94c 100644
--- a/libelftc/elftc_bfd_find_target.3
+++ b/libelftc/elftc_bfd_find_target.3
@@ -21,9 +21,9 @@
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
-.\" $Id: elftc_bfd_find_target.3 3645 2018-10-15 20:17:14Z jkoshy $
+.\" $Id: elftc_bfd_find_target.3 3752 2019-06-28 01:12:53Z emaste $
.\"
-.Dd November 30, 2011
+.Dd June 27, 2019
.Dt ELFTC_BFD_FIND_TARGET 3
.Os
.Sh NAME
@@ -76,6 +76,9 @@ Known descriptor names and their properties include:
.It Li elf32-powerpc Ta ELF Ta MSB Ta 32
.It Li elf32-powerpc-freebsd Ta ELF Ta MSB Ta 32
.It Li elf32-powerpcle Ta ELF Ta LSB Ta 32
+.It Li elf32-riscv Ta ELF Ta LSB Ta 32
+.It Li elf64-riscv Ta ELF Ta LSB Ta 64
+.It Li elf64-riscv-freebsd Ta ELF Ta LSB Ta 64
.It Li elf32-sh Ta ELF Ta MSB Ta 32
.It Li elf32-shl Ta ELF Ta LSB Ta 32
.It Li elf32-sh-nbsd Ta ELF Ta MSB Ta 32
diff --git a/libelftc/elftc_reloc_type_str.c b/libelftc/elftc_reloc_type_str.c
index fdad9a6448c6..4fa715ae0734 100644
--- a/libelftc/elftc_reloc_type_str.c
+++ b/libelftc/elftc_reloc_type_str.c
@@ -402,6 +402,8 @@ elftc_reloc_type_str(unsigned int mach, unsigned int type)
case 22: return "R_MIPS_GOT_HI16";
case 23: return "R_MIPS_GOT_LO16";
case 24: return "R_MIPS_SUB";
+ case 28: return "R_MIPS_HIGHER";
+ case 29: return "R_MIPS_HIGHEST";
case 30: return "R_MIPS_CALLHI16";
case 31: return "R_MIPS_CALLLO16";
case 37: return "R_MIPS_JALR";
diff --git a/libelftc/elftc_string_table.c b/libelftc/elftc_string_table.c
index bba9ac6a76cd..f9f50fa91f07 100644
--- a/libelftc/elftc_string_table.c
+++ b/libelftc/elftc_string_table.c
@@ -36,7 +36,7 @@
#include "libelftc.h"
#include "_libelftc.h"
-ELFTC_VCSID("$Id: elftc_string_table.c 2869 2013-01-06 13:29:18Z jkoshy $");
+ELFTC_VCSID("$Id: elftc_string_table.c 3750 2019-06-28 01:12:10Z emaste $");
#define ELFTC_STRING_TABLE_DEFAULT_SIZE (4*1024)
#define ELFTC_STRING_TABLE_EXPECTED_STRING_SIZE 16
@@ -44,7 +44,7 @@ ELFTC_VCSID("$Id: elftc_string_table.c 2869 2013-01-06 13:29:18Z jkoshy $");
#define ELFTC_STRING_TABLE_POOL_SIZE_INCREMENT (4*1024)
struct _Elftc_String_Table_Entry {
- int ste_idx;
+ ssize_t ste_idx;
SLIST_ENTRY(_Elftc_String_Table_Entry) ste_next;
};
@@ -64,9 +64,9 @@ struct _Elftc_String_Table_Entry {
} while (0)
struct _Elftc_String_Table {
- unsigned int st_len; /* length and flags */
+ size_t st_len; /* length and flags */
int st_nbuckets;
- int st_string_pool_size;
+ size_t st_string_pool_size;
char *st_string_pool;
SLIST_HEAD(_Elftc_String_Table_Bucket,
_Elftc_String_Table_Entry) st_buckets[];
@@ -86,7 +86,7 @@ elftc_string_table_find_hash_entry(Elftc_String_Table *st, const char *string,
*rhashindex = hashindex;
SLIST_FOREACH(ste, &st->st_buckets[hashindex], ste_next) {
- s = st->st_string_pool + abs(ste->ste_idx);
+ s = st->st_string_pool + labs(ste->ste_idx);
assert(s > st->st_string_pool &&
s < st->st_string_pool + st->st_string_pool_size);
@@ -102,7 +102,7 @@ static int
elftc_string_table_add_to_pool(Elftc_String_Table *st, const char *string)
{
char *newpool;
- int len, newsize, stlen;
+ size_t len, newsize, stlen;
len = strlen(string) + 1; /* length, including the trailing NUL */
stlen = ELFTC_STRING_TABLE_LENGTH(st);
@@ -119,17 +119,17 @@ elftc_string_table_add_to_pool(Elftc_String_Table *st, const char *string)
st->st_string_pool_size = newsize;
}
- strcpy(st->st_string_pool + stlen, string);
+ memcpy(st->st_string_pool + stlen, string, len);
ELFTC_STRING_TABLE_UPDATE_LENGTH(st, stlen + len);
return (stlen);
}
Elftc_String_Table *
-elftc_string_table_create(int sizehint)
+elftc_string_table_create(size_t sizehint)
{
- int n, nbuckets, tablesize;
struct _Elftc_String_Table *st;
+ int n, nbuckets, tablesize;
if (sizehint < ELFTC_STRING_TABLE_DEFAULT_SIZE)
sizehint = ELFTC_STRING_TABLE_DEFAULT_SIZE;
@@ -167,21 +167,19 @@ elftc_string_table_destroy(Elftc_String_Table *st)
for (n = 0; n < st->st_nbuckets; n++)
SLIST_FOREACH_SAFE(s, &st->st_buckets[n], ste_next, t)
- free(s);
+ free(s);
free(st->st_string_pool);
free(st);
-
- return;
}
Elftc_String_Table *
-elftc_string_table_from_section(Elf_Scn *scn, int sizehint)
+elftc_string_table_from_section(Elf_Scn *scn, size_t sizehint)
{
- int len;
Elf_Data *d;
GElf_Shdr sh;
const char *s, *end;
Elftc_String_Table *st;
+ size_t len;
/* Verify the type of the section passed in. */
if (gelf_getshdr(scn, &sh) == NULL ||
@@ -237,7 +235,8 @@ elftc_string_table_image(Elftc_String_Table *st, size_t *size)
char *r, *s, *end;
struct _Elftc_String_Table_Entry *ste;
struct _Elftc_String_Table_Bucket *head;
- int copied, hashindex, offset, length, newsize;
+ size_t copied, offset, length, newsize;
+ int hashindex;
/*
* For the common case of a string table has not seen
@@ -305,8 +304,9 @@ elftc_string_table_image(Elftc_String_Table *st, size_t *size)
size_t
elftc_string_table_insert(Elftc_String_Table *st, const char *string)
{
- int hashindex, idx;
struct _Elftc_String_Table_Entry *ste;
+ ssize_t idx;
+ int hashindex;
hashindex = 0;
@@ -318,7 +318,7 @@ elftc_string_table_insert(Elftc_String_Table *st, const char *string)
if ((ste = malloc(sizeof(*ste))) == NULL)
return (0);
if ((ste->ste_idx = elftc_string_table_add_to_pool(st,
- string)) == 0) {
+ string)) == 0) {
free(ste);
return (0);
}
@@ -328,7 +328,7 @@ elftc_string_table_insert(Elftc_String_Table *st, const char *string)
idx = ste->ste_idx;
if (idx < 0) /* Undelete. */
- ste->ste_idx = idx = (- idx);
+ ste->ste_idx = idx = -idx;
return (idx);
}
@@ -336,8 +336,9 @@ elftc_string_table_insert(Elftc_String_Table *st, const char *string)
size_t
elftc_string_table_lookup(Elftc_String_Table *st, const char *string)
{
- int hashindex, idx;
struct _Elftc_String_Table_Entry *ste;
+ ssize_t idx;
+ int hashindex;
ste = elftc_string_table_find_hash_entry(st, string, &hashindex);
@@ -352,17 +353,17 @@ elftc_string_table_lookup(Elftc_String_Table *st, const char *string)
int
elftc_string_table_remove(Elftc_String_Table *st, const char *string)
{
- int idx;
struct _Elftc_String_Table_Entry *ste;
+ ssize_t idx;
ste = elftc_string_table_find_hash_entry(st, string, NULL);
if (ste == NULL || (idx = ste->ste_idx) < 0)
return (ELFTC_FAILURE);
- assert(idx > 0 && idx < (int) ELFTC_STRING_TABLE_LENGTH(st));
+ assert(idx > 0 && (size_t)idx < ELFTC_STRING_TABLE_LENGTH(st));
- ste->ste_idx = (- idx);
+ ste->ste_idx = -idx;
ELFTC_STRING_TABLE_SET_COMPACTION_FLAG(st);
diff --git a/libelftc/elftc_string_table_create.3 b/libelftc/elftc_string_table_create.3
index 387ad72a3727..47784639dd09 100644
--- a/libelftc/elftc_string_table_create.3
+++ b/libelftc/elftc_string_table_create.3
@@ -22,9 +22,9 @@
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
-.\" $Id: elftc_string_table_create.3 3645 2018-10-15 20:17:14Z jkoshy $
+.\" $Id: elftc_string_table_create.3 3750 2019-06-28 01:12:10Z emaste $
.\"
-.Dd January 5, 2013
+.Dd June 27, 2019
.Dt ELFTC_STRING_TABLE_CREATE 3
.Os
.Sh NAME
@@ -40,11 +40,11 @@
.Sh SYNOPSIS
.In libelftc.h
.Ft "Elftc_String_Table *"
-.Fn elftc_string_table_create "int sizehint"
-.Ft int
+.Fn elftc_string_table_create "size_t sizehint"
+.Ft void
.Fn elftc_string_table_destroy "Elftc_String_Table *table"
.Ft "Elftc_String_Table *"
-.Fn elftc_string_table_from_section "Elf_Scn *scn" "int sizehint"
+.Fn elftc_string_table_from_section "Elf_Scn *scn" "size_t sizehint"
.Ft "const char *"
.Fo elftc_string_table_image
.Fa "Elftc_String_Table *table"
@@ -144,7 +144,7 @@ looks up the string referenced by argument
in the string table specified by argument
.Ar table ,
and if found, returns the offset associated with the string.
-The returned offset will be valid till the next call to function
+The returned offset will be valid until the next call to
.Fn elftc_string_table_image .
.Pp
Function
diff --git a/libelftc/libelftc.h b/libelftc/libelftc.h
index a235097e6910..244c029c9fb2 100644
--- a/libelftc/libelftc.h
+++ b/libelftc/libelftc.h
@@ -24,7 +24,7 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $FreeBSD: users/kaiwang27/elftc/libelftc.h 392 2009-05-31 19:17:46Z kaiwang27 $
- * $Id: libelftc.h 3489 2016-08-31 00:12:15Z emaste $
+ * $Id: libelftc.h 3744 2019-06-28 00:41:47Z emaste $
*/
#ifndef _LIBELFTC_H_
@@ -77,10 +77,10 @@ int elftc_demangle(const char *_mangledname, char *_buffer,
size_t _bufsize, unsigned int _flags);
const char *elftc_reloc_type_str(unsigned int mach, unsigned int type);
int elftc_set_timestamps(const char *_filename, struct stat *_sb);
-Elftc_String_Table *elftc_string_table_create(int _hint);
+Elftc_String_Table *elftc_string_table_create(size_t _sizehint);
void elftc_string_table_destroy(Elftc_String_Table *_table);
Elftc_String_Table *elftc_string_table_from_section(Elf_Scn *_scn,
- int _hint);
+ size_t _sizehint);
const char *elftc_string_table_image(Elftc_String_Table *_table,
size_t *_sz);
size_t elftc_string_table_insert(Elftc_String_Table *_table,
diff --git a/libelftc/libelftc_bfdtarget.c b/libelftc/libelftc_bfdtarget.c
index 48b67a00c75c..5bbf89ba78fa 100644
--- a/libelftc/libelftc_bfdtarget.c
+++ b/libelftc/libelftc_bfdtarget.c
@@ -30,7 +30,7 @@
#include "_libelftc.h"
-ELFTC_VCSID("$Id: libelftc_bfdtarget.c 3516 2017-02-10 02:33:08Z emaste $");
+ELFTC_VCSID("$Id: libelftc_bfdtarget.c 3752 2019-06-28 01:12:53Z emaste $");
struct _Elftc_Bfd_Target _libelftc_targets[] = {
@@ -316,6 +316,31 @@ struct _Elftc_Bfd_Target _libelftc_targets[] = {
},
{
+ .bt_name = "elf32-riscv",
+ .bt_type = ETF_ELF,
+ .bt_byteorder = ELFDATA2LSB,
+ .bt_elfclass = ELFCLASS32,
+ .bt_machine = EM_RISCV,
+ },
+
+ {
+ .bt_name = "elf64-riscv",
+ .bt_type = ETF_ELF,
+ .bt_byteorder = ELFDATA2LSB,
+ .bt_elfclass = ELFCLASS64,
+ .bt_machine = EM_RISCV,
+ },
+
+ {
+ .bt_name = "elf64-riscv-freebsd",
+ .bt_type = ETF_ELF,
+ .bt_byteorder = ELFDATA2MSB,
+ .bt_elfclass = ELFCLASS64,
+ .bt_machine = EM_RISCV,
+ .bt_osabi = ELFOSABI_FREEBSD,
+ },
+
+ {
.bt_name = "elf64-sh64",
.bt_type = ETF_ELF,
.bt_byteorder = ELFDATA2MSB,
diff --git a/libelftc/make-toolchain-version b/libelftc/make-toolchain-version
index 0cdf370cc32b..cb0f437d069d 100755
--- a/libelftc/make-toolchain-version
+++ b/libelftc/make-toolchain-version
@@ -3,7 +3,7 @@
# This script generates a project-wide version identifier for use by
# the `elftc_version()' API.
#
-# $Id: make-toolchain-version 3414 2016-02-16 22:55:28Z jkoshy $
+# $Id: make-toolchain-version 3731 2019-04-06 14:28:34Z jkoshy $
#
# Defaults.
@@ -33,6 +33,32 @@ usage()
exit 1
}
+# Determine the revision number for the source tree.
+#
+# - If CVS is detected, we use the string `unknown'.
+# - If SVN is detected, we use the `svninfo' tool to determine the
+# in-tree revision number.
+# - Otherwise, we use `git --describe'.
+get_revision_string()
+{
+ v="unknown:unknown"
+ if [ -d CVS ]; then # Look for CVS (NetBSD).
+ v="cvs:unknown"
+ elif [ -d .svn ]; then # An SVN checkout (SourceForge or FreeBSD).
+ svnversion="$(svnversion 2>/dev/null)"
+ if [ -n "${svnversion}" ]; then
+ v="svn:${svnversion}"
+ fi
+ else # Try git (DragonflyBSD).
+ gitversion="$(git describe --all --dirty --long 2> /dev/null)"
+ if [ -n "${gitversion}" ]; then
+ v="git:${gitversion}"
+ fi
+ fi
+
+ echo "${v}"
+}
+
#
# Parse options.
#
@@ -51,37 +77,14 @@ done
[ -n "${top}" ] || usage
-# Try to determine the in-tree revision number.
-#
-# This script attempts to handle the case where our sources have been
-# incorporated into an operating system's base sources.
-#
-# - If SVN is detected, we use the `svninfo' tool to determine the
-# in-tree revision number.
-# - If CVS is detected, we use the string `unknown'.
-# - Otherwise, we use `git --describe'.
-
curdir=`pwd`
cd ${top} || usage "ERROR: Cannot change directory to \"${top}\"."
-if [ -d CVS ]; then # Look for CVS (NetBSD).
- versionstring=" cvs:unknown"
-else # Try git (DragonFlyBSD).
- gitversion="$(git describe --all --dirty --long 2> /dev/null)"
- if [ -n "${gitversion}" ]; then
- versionstring=" git:${gitversion}"
- else # Assume an SVN checkout (SourceForge or FreeBSD).
- svnversion="$(svnversion)"
- if [ -n "${svnversion}" ]; then
- versionstring=" svn:$(svnversion)"
- fi
- fi
-fi
-
-if [ -z "${versionstring}" ]; then
- echo "ERROR: cannot determine a revision number." 1>&2
+# Determine the in-tree revision number.
+versionstring="$(get_revision_string)" || {
+ echo "ERROR: cannot determine a revision number." 1>&2;
exit 1
-fi
+}
cd ${curdir} || usage "Cannot change back to ${curdir}."
@@ -100,7 +103,7 @@ cat > ${tmpfile} <<EOF
const char *
elftc_version(void)
{
- return "${elftcname} ${version} ${buildhost}${versionstring}";
+ return "${elftcname} ${version} ${buildhost} ${versionstring}";
}
EOF