Skip to content

Commit c2e27ef

Browse files
committed
cgen: remove obfuscation (strip should be used instead); temporary fix for usecache + toml
1 parent 04f9a21 commit c2e27ef

5 files changed

Lines changed: 16 additions & 85 deletions

File tree

‎vlib/v/builder/rebuilding.v‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ fn (mut b Builder) v_build_module(vexe string, imp_path string) {
190190
$if trace_v_build_module ? {
191191
eprintln('> Builder.v_build_module: ${rebuild_cmd}')
192192
}
193+
// eprintln('> Builder.v_build_module: ${rebuild_cmd}')
193194
os.system(rebuild_cmd)
194195
}
195196

‎vlib/v/gen/c/cgen.v‎

Lines changed: 12 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ pub:
277277
header string // produced output for out.h (-parallel-cc)
278278
res_builder strings.Builder // produced output (complete)
279279
out_str string // produced output from g.out
280-
out0_str string // helpers output (auto fns, dump fns) for out_0.c (-parallel-cc)
280+
out0_str string // helpers output (auto fns, dump fns) for out_0.c (-parallel-cc)
281281
extern_str string // extern chunk for (-parallel-cc)
282282
out_fn_start_pos []int // fn decl positions
283283
}
@@ -355,15 +355,6 @@ pub fn gen(files []&ast.File, mut table ast.Table, pref_ &pref.Preferences) GenO
355355

356356
global_g.type_resolver = type_resolver.TypeResolver.new(table, global_g)
357357
global_g.comptime = &global_g.type_resolver.info
358-
/*
359-
global_g.out_parallel = []strings.Builder{len: nr_cpus}
360-
for i in 0 .. nr_cpus {
361-
global_g.out_parallel[i] = strings.new_builder(100000)
362-
global_g.out_parallel[i].writeln('#include "out.h"\n')
363-
}
364-
println('LEN=')
365-
println(global_g.out_parallel.len)
366-
*/
367358
// anon fn may include assert and thus this needs
368359
// to be included before any test contents are written
369360
if pref_.is_test {
@@ -516,18 +507,27 @@ pub fn gen(files []&ast.File, mut table ast.Table, pref_ &pref.Preferences) GenO
516507

517508
// to make sure type idx's are the same in cached mods
518509
if g.pref.build_mode == .build_module {
510+
is_toml := g.pref.path.contains('/toml')
519511
for idx, sym in g.table.type_symbols {
520512
if idx in [0, 31] {
521513
continue
522514
}
523-
g.definitions.writeln('int _v_type_idx_${sym.cname}();')
515+
if is_toml && sym.cname.contains('map[string]') {
516+
// Temporary hack to make toml work with -usecache TODO remove
517+
continue
518+
}
519+
g.definitions.writeln('int _v_type_idx_${sym.cname}(); // 1build module ${g.pref.path}')
524520
}
525521
} else if g.pref.use_cache {
522+
is_toml := g.pref.path.contains('/toml')
526523
for idx, sym in g.table.type_symbols {
527524
if idx in [0, 31] {
528525
continue
529526
}
530-
g.definitions.writeln('int _v_type_idx_${sym.cname}() { return ${idx}; };')
527+
if is_toml && sym.cname.contains('map[string]') {
528+
continue
529+
}
530+
g.definitions.writeln('int _v_type_idx_${sym.cname}() { return ${idx}; }; //lol ${g.pref.path}')
531531
}
532532
}
533533

@@ -1059,29 +1059,6 @@ pub fn (mut g Gen) init() {
10591059
if g.pref.is_livemain || g.pref.is_liveshared {
10601060
g.generate_hotcode_reloading_declarations()
10611061
}
1062-
// Obfuscate only functions in the main module for now.
1063-
// Generate the obf_ast.
1064-
if g.pref.obfuscate {
1065-
mut i := 0
1066-
// fns
1067-
for key, f in g.table.fns {
1068-
if f.mod != 'main' && key != 'main' {
1069-
continue
1070-
}
1071-
g.obf_table[key] = '_f${i}'
1072-
i++
1073-
}
1074-
// methods
1075-
for type_sym in g.table.type_symbols {
1076-
if type_sym.mod != 'main' {
1077-
continue
1078-
}
1079-
for method in type_sym.methods {
1080-
g.obf_table[type_sym.name + '.' + method.name] = '_f${i}'
1081-
i++
1082-
}
1083-
}
1084-
}
10851062
// we know that this is being called before the multi-threading starts
10861063
// and this is being called in the main thread, so we can mutate the table
10871064
mut muttable := unsafe { &ast.Table(g.table) }
@@ -5357,14 +5334,6 @@ fn (mut g Gen) ident(node ast.Ident) {
53575334
name = g.generic_fn_name(node.concrete_types, name)
53585335
}
53595336
}
5360-
5361-
if g.pref.obfuscate && g.cur_mod.name == 'main' && name.starts_with('main__') {
5362-
key := node.name
5363-
g.write('/* obf identfn: ${key} */')
5364-
name = g.obf_table[key] or {
5365-
panic('cgen: obf name "${key}" not found, this should never happen')
5366-
}
5367-
}
53685337
}
53695338
g.write(g.get_ternary_name(name))
53705339
if is_auto_heap {

‎vlib/v/gen/c/fn.v‎

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -256,18 +256,6 @@ fn (mut g Gen) gen_fn_decl(node &ast.FnDecl, skip bool) {
256256

257257
mut name := g.c_fn_name(node)
258258
type_name := g.ret_styp(g.unwrap_generic(node.return_type))
259-
if g.pref.obfuscate && g.cur_mod.name == 'main' && name.starts_with('main__') && !node.is_main
260-
&& node.name != 'str' {
261-
mut key := node.name
262-
if node.is_method {
263-
sym := g.table.sym(node.receiver.typ)
264-
key = sym.name + '.' + node.name
265-
}
266-
g.writeln('/* obf: ${key} */')
267-
name = g.obf_table[key] or {
268-
panic('cgen: fn_decl: obf name "${key}" not found, this should never happen')
269-
}
270-
}
271259
// Live functions are protected by a mutex, because otherwise they
272260
// can be changed by the live reload thread, *while* they are
273261
// running, with unpredictable results (usually just crashing).
@@ -1668,15 +1656,6 @@ fn (mut g Gen) method_call(node ast.CallExpr) {
16681656
if left_sym.kind == .chan && node.name in ['close', 'try_pop', 'try_push'] {
16691657
name = 'sync__Channel_${node.name}'
16701658
}
1671-
if g.pref.obfuscate && g.cur_mod.name == 'main' && name.starts_with('main__')
1672-
&& node.name != 'str' {
1673-
sym := g.table.sym(node.receiver_type)
1674-
key := sym.name + '.' + node.name
1675-
g.write('/* obf method call: ${key} */')
1676-
name = g.obf_table[key] or {
1677-
panic('cgen: obf name "${key}" not found, this should never happen')
1678-
}
1679-
}
16801659
mut is_range_slice := false
16811660
if node.receiver_type.is_ptr() && !left_type.is_ptr() {
16821661
if node.left is ast.IndexExpr {
@@ -2019,14 +1998,6 @@ fn (mut g Gen) fn_call(node ast.CallExpr) {
20191998
}
20201999
}
20212000
}
2022-
// Obfuscate only functions in the main module for now
2023-
if g.pref.obfuscate && g.cur_mod.name == 'main' && name.starts_with('main__') {
2024-
key := node.name
2025-
g.write('/* obf call: ${key} */')
2026-
name = g.obf_table[key] or {
2027-
panic('cgen: obf name "${key}" not found, this should never happen')
2028-
}
2029-
}
20302001
if !is_selector_call {
20312002
if func := g.table.find_fn(node_name) {
20322003
mut concrete_types := node.concrete_types.map(g.unwrap_generic(it))

‎vlib/v/gen/c/spawn_and_go.v‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,6 @@ fn (mut g Gen) spawn_and_go_expr(node ast.SpawnExpr, mode SpawnGoMode) {
7171
}
7272
}
7373
name = util.no_dots(name)
74-
if g.pref.obfuscate && g.cur_mod.name == 'main' && name.starts_with('main__') {
75-
mut key := expr.name
76-
if expr.is_method {
77-
sym := g.table.sym(expr.receiver_type)
78-
key = sym.name + '.' + expr.name
79-
}
80-
g.write('/* obf go: ${key} */')
81-
name = g.obf_table[key] or {
82-
panic('cgen: obf name "${key}" not found, this should never happen')
83-
}
84-
}
8574
g.empty_line = true
8675
g.writeln('// start go')
8776
wrapper_struct_name := 'thread_arg_' + name

‎vlib/v/pref/pref.v‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ pub mut:
137137
profile_fns []string // when set, profiling will be off by default, but inside these functions (and what they call) it will be on.
138138
translated bool // `v translate doom.v` are we running V code translated from C? allow globals, ++ expressions, etc
139139
translated_go bool = true // Are we running V code translated from Go? Allow err shadowing
140-
obfuscate bool // `v -obf program.v`, renames functions to "f_XXX"
140+
obfuscate_removed bool // `v -obf program.v`, renames functions to "f_XXX". REMOVED. Use `strip` instead
141141
hide_auto_str bool // `v -hide-auto-str program.v`, doesn't generate str() with struct data
142142
// Note: passing -cg instead of -g will set is_vlines to false and is_debug to true, thus making v generate cleaner C files,
143143
// which are sometimes easier to debug / inspect manually than the .tmp.c files by plain -g (when/if v line number generation breaks).
@@ -688,7 +688,8 @@ pub fn parse_args_and_show_errors(known_external_commands []string, args []strin
688688
res.is_stats = true
689689
}
690690
'-obf', '-obfuscate' {
691-
res.obfuscate = true
691+
println('obfuscation has been removed; use `strip` on the resulting binary instead')
692+
res.obfuscate_removed = true
692693
}
693694
'-hide-auto-str' {
694695
res.hide_auto_str = true

0 commit comments

Comments
 (0)