/*
* sanitize_symbol:
*
- * Modify SYMBOL so it only includes characters permissible in symbols.
+ * Return a modified version of S which only includes characters permissible in symbols.
*/
-static void
-sanitize_symbol (char *symbol)
+static char*
+sanitize_symbol (MonoAotCompile *acfg, char *s)
{
- int i, len = strlen (symbol);
+ gboolean process = FALSE;
+ int i, len;
+ GString *gs;
+ char *res;
+
+ if (!s)
+ return s;
+ len = strlen (s);
for (i = 0; i < len; ++i)
- if (!isalnum (symbol [i]) && (symbol [i] != '_'))
- symbol [i] = '_';
+ if (!(s [i] <= 0x7f && (isalnum (s [i]) || s [i] == '_')))
+ process = TRUE;
+ if (!process)
+ return s;
+
+ gs = g_string_sized_new (len);
+ for (i = 0; i < len; ++i) {
+ guint8 c = s [i];
+ if (c <= 0x7f && (isalnum (c) || c == '_')) {
+ g_string_append_c (gs, c);
+ } else if (c > 0x7f) {
+ /* multi-byte utf8 */
+ g_string_append_printf (gs, "_0x%x", c);
+ i ++;
+ c = s [i];
+ while (c >> 6 == 0x2) {
+ g_string_append_printf (gs, "%x", c);
+ i ++;
+ c = s [i];
+ }
+ g_string_append_printf (gs, "_");
+ i --;
+ } else {
+ g_string_append_c (gs, '_');
+ }
+ }
+
+ res = mono_mempool_strdup (acfg->mempool, gs->str);
+ g_string_free (gs, TRUE);
+ return res;
}
static char*
get_plt_entry_debug_sym (MonoAotCompile *acfg, MonoJumpInfo *ji, GHashTable *cache)
{
char *debug_sym = NULL;
+ char *s;
switch (ji->type) {
case MONO_PATCH_INFO_METHOD:
debug_sym = g_strdup_printf ("plt__jit_icall_%s", ji->data.name);
break;
case MONO_PATCH_INFO_CLASS_INIT:
- debug_sym = g_strdup_printf ("plt__class_init_%s", mono_type_get_name (&ji->data.klass->byval_arg));
- sanitize_symbol (debug_sym);
+ s = mono_type_get_name (&ji->data.klass->byval_arg);
+ debug_sym = g_strdup_printf ("plt__class_init_%s", s);
+ g_free (s);
break;
case MONO_PATCH_INFO_RGCTX_FETCH:
debug_sym = g_strdup_printf ("plt__rgctx_fetch_%d", acfg->label_generator ++);
break;
}
- return debug_sym;
+ return sanitize_symbol (acfg, debug_sym);
}
/*