summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammed Khoory <mkhoory@eiast.ae>2013-11-04 10:49:44 +0900
committerChris Johns <chrisj@rtems.org>2014-09-01 09:32:37 +1000
commitd7aca117e2aaa7dca6db40f182f64fd66644a198 (patch)
tree2328ea34464afe9141c1d26d33050efab537c681
parent0b81accba708e028d3e9828522907ca4fda77125 (diff)
Fixed comparison of ELF object names
-rw-r--r--rtl-obj.c38
-rw-r--r--rtl-obj.h16
-rw-r--r--rtl.c7
3 files changed, 46 insertions, 15 deletions
diff --git a/rtl-obj.c b/rtl-obj.c
index 7e20f46..532756a 100644
--- a/rtl-obj.c
+++ b/rtl-obj.c
@@ -115,11 +115,14 @@ rtems_rtl_obj_unresolved (rtems_rtl_obj_t* obj)
return (obj->flags & RTEMS_RTL_OBJ_UNRESOLVED) != 0 ? true : false;
}
-static bool
-rtems_rtl_obj_parse_name (rtems_rtl_obj_t* obj, const char* name)
+bool
+rtems_rtl_parse_name (const char* name,
+ const char** aname,
+ const char** oname,
+ int* ooffset)
{
- const char* aname = NULL;
- const char* oname = NULL;
+ const char* laname = NULL;
+ const char* loname = NULL;
const char* colon;
const char* end;
@@ -133,14 +136,14 @@ rtems_rtl_obj_parse_name (rtems_rtl_obj_t* obj, const char* name)
if (colon == NULL || colon < strrchr(name, '/'))
colon = end;
- oname = rtems_rtl_alloc_new (RTEMS_RTL_ALLOC_OBJECT, colon - name + 1, true);
+ loname = rtems_rtl_alloc_new (RTEMS_RTL_ALLOC_OBJECT, colon - name + 1, true);
if (!oname)
{
rtems_rtl_set_error (ENOMEM, "no memory for object file name");
return false;
}
- memcpy ((void*) oname, name, colon - name);
+ memcpy ((void*) loname, name, colon - name);
/*
* If the pointers match there is no ':' delimiter.
@@ -153,7 +156,7 @@ rtems_rtl_obj_parse_name (rtems_rtl_obj_t* obj, const char* name)
* The file name is an archive and the object file name is next after the
* delimiter. Move the pointer to the archive name.
*/
- aname = oname;
+ laname = loname;
++colon;
/*
@@ -166,15 +169,15 @@ rtems_rtl_obj_parse_name (rtems_rtl_obj_t* obj, const char* name)
at = end;
- oname = rtems_rtl_alloc_new (RTEMS_RTL_ALLOC_OBJECT, at - colon + 1, true);
- if (!oname)
+ loname = rtems_rtl_alloc_new (RTEMS_RTL_ALLOC_OBJECT, at - colon + 1, true);
+ if (!loname)
{
- rtems_rtl_alloc_del (RTEMS_RTL_ALLOC_OBJECT, (void*) aname);
+ rtems_rtl_alloc_del (RTEMS_RTL_ALLOC_OBJECT, (void*) laname);
rtems_rtl_set_error (ENOMEM, "no memory for object file name");
return false;
}
- memcpy ((void*) oname, colon, at - colon);
+ memcpy ((void*) loname, colon, at - colon);
if (at != end)
{
@@ -183,17 +186,22 @@ rtems_rtl_obj_parse_name (rtems_rtl_obj_t* obj, const char* name)
* does not parse 0 will be returned and the archive will be
* searched.
*/
- obj->ooffset = strtoul (at + 1, 0, 0);
+ *ooffset = strtoul (at + 1, 0, 0);
}
}
- obj->oname = oname;
- obj->aname = aname;
-
+ *oname = loname;
+ *aname = laname;
return true;
}
static bool
+rtems_rtl_obj_parse_name (rtems_rtl_obj_t* obj, const char* name)
+{
+ return rtems_rtl_parse_name (name, &(obj->aname), &(obj->oname), &(obj->ooffset));
+}
+
+static bool
rtems_rtl_seek_read (int fd, off_t off, size_t len, uint8_t* buffer)
{
if (lseek (fd, off, SEEK_SET) < 0)
diff --git a/rtl-obj.h b/rtl-obj.h
index 2f7c403..7e200d6 100644
--- a/rtl-obj.h
+++ b/rtl-obj.h
@@ -281,6 +281,22 @@ bool rtems_rtl_obj_free (rtems_rtl_obj_t* obj);
bool rtems_rtl_obj_unresolved (rtems_rtl_obj_t* obj);
/**
+ * Parses a filename and returns newly allocated strings with the archive name,
+ * object name, and the object's offset
+ *
+ * @param name The filename of the object
+ * @param aname Address of a string pointer that holds the archive name
+ * @param oname Address of a string pointer that holds the object name
+ * @param ooffset Address of an int that holds the object offset
+ * @retval true The parsing was successful
+ * @retval false The parsing was unsuccessful
+ */
+bool rtems_rtl_parse_name (const char* name,
+ const char** aname,
+ const char** oname,
+ int* ooffset);
+
+/**
* Load the object file.
*
* @param obj The object file's descriptor.
diff --git a/rtl.c b/rtl.c
index 9429046..3e96742 100644
--- a/rtl.c
+++ b/rtl.c
@@ -375,6 +375,13 @@ rtems_rtl_obj_t*
rtems_rtl_find_obj (const char* name)
{
rtems_chain_node* node;
+ rtems_rtl_obj_t* found = NULL;
+ const char* aname = NULL;
+ const char* oname = NULL;
+ int ooffset;
+
+ if (!rtems_rtl_parse_name (name, &aname, &oname, &ooffset))
+ return NULL;
node = rtems_chain_first (&rtl->objects);