diff options
| -rw-r--r-- | src/lj_clib.c | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/src/lj_clib.c b/src/lj_clib.c index 9f69b969..937b1258 100644 --- a/src/lj_clib.c +++ b/src/lj_clib.c | |||
| @@ -60,25 +60,39 @@ static const char *clib_extname(lua_State *L, const char *name) | |||
| 60 | return name; | 60 | return name; |
| 61 | } | 61 | } |
| 62 | 62 | ||
| 63 | /* Check for a recognized ld script line. */ | ||
| 64 | static const char *clib_check_lds(lua_State *L, const char *buf) | ||
| 65 | { | ||
| 66 | char *p, *e; | ||
| 67 | if ((!strncmp(buf, "GROUP", 5) || !strncmp(buf, "INPUT", 5)) && | ||
| 68 | (p = strchr(buf, '('))) { | ||
| 69 | while (*++p == ' ') ; | ||
| 70 | for (e = p; *e && *e != ' ' && *e != ')'; e++) ; | ||
| 71 | return strdata(lj_str_new(L, p, e-p)); | ||
| 72 | } | ||
| 73 | return NULL; | ||
| 74 | } | ||
| 75 | |||
| 63 | /* Quick and dirty solution to resolve shared library name from ld script. */ | 76 | /* Quick and dirty solution to resolve shared library name from ld script. */ |
| 64 | static const char *clib_resolve_lds(lua_State *L, const char *name) | 77 | static const char *clib_resolve_lds(lua_State *L, const char *name) |
| 65 | { | 78 | { |
| 66 | FILE *fp = fopen(name, "r"); | 79 | FILE *fp = fopen(name, "r"); |
| 80 | const char *p = NULL; | ||
| 67 | if (fp) { | 81 | if (fp) { |
| 68 | char *p, *e, buf[256]; | 82 | char buf[256]; |
| 69 | if (fgets(buf, sizeof(buf), fp) && !strncmp(buf, "/* GNU ld script", 16)) { | 83 | if (fgets(buf, sizeof(buf), fp)) { |
| 70 | while (fgets(buf, sizeof(buf), fp)) { | 84 | if (!strncmp(buf, "/* GNU ld script", 16)) { /* ld script magic? */ |
| 71 | if (!strncmp(buf, "GROUP", 5) && (p = strchr(buf, '('))) { | 85 | while (fgets(buf, sizeof(buf), fp)) { /* Check all lines. */ |
| 72 | while (*++p == ' ') ; | 86 | p = clib_check_lds(L, buf); |
| 73 | for (e = p; *e && *e != ' ' && *e != ')'; e++) ; | 87 | if (p) break; |
| 74 | fclose(fp); | ||
| 75 | return strdata(lj_str_new(L, p, e-p)); | ||
| 76 | } | 88 | } |
| 89 | } else { /* Otherwise check only the first line. */ | ||
| 90 | p = clib_check_lds(L, buf); | ||
| 77 | } | 91 | } |
| 78 | } | 92 | } |
| 79 | fclose(fp); | 93 | fclose(fp); |
| 80 | } | 94 | } |
| 81 | return NULL; | 95 | return p; |
| 82 | } | 96 | } |
| 83 | 97 | ||
| 84 | static void *clib_loadlib(lua_State *L, const char *name, int global) | 98 | static void *clib_loadlib(lua_State *L, const char *name, int global) |
