Skip to content

Commit fc5615a

Browse files
committed
support msvc LTO build
1 parent 5299276 commit fc5615a

4 files changed

Lines changed: 64 additions & 8 deletions

File tree

memory_view.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131

3232
// Exported Object Registry
3333

34+
#ifdef _MSC_VER
35+
#pragma comment(linker, "/export:rb_memory_view_exported_object_registry,DATA"))
36+
#endif
37+
3438
static st_table *exported_object_table = NULL;
3539
VALUE rb_memory_view_exported_object_registry = Qundef;
3640

st.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3186,7 +3186,7 @@ set_foreach_check(set_table *tab, set_foreach_check_callback_func *func, st_data
31863186

31873187
/* Set up array KEYS by at most SIZE keys of head table TAB entries.
31883188
Return the number of keys set up in array KEYS. */
3189-
inline st_index_t
3189+
st_index_t
31903190
set_keys(set_table *tab, st_data_t *keys, st_index_t size)
31913191
{
31923192
st_index_t i, bound;

win32/Makefile.sub

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,10 +1158,25 @@ $(LIBRUBY_SO): $(LIBRUBY_A) $(DLDOBJS) $(RUBYDEF) $(RUBY_SO_NAME).res
11581158
$(LIBRUBY_DLDFLAGS)
11591159
@$(RM) dummy.lib dummy.exp
11601160

1161+
!if 0
1162+
11611163
$(RUBYDEF): $(LIBRUBY_A) $(RBCONFIG)
11621164
$(ECHO) generating $(@:\=/)
11631165
$(Q) $(BOOTSTRAPRUBY_COMMAND) $(srcdir)/win32/mkexports.rb \
11641166
-output=$@ -arch=$(ARCH) $(LIBRUBY_A)
1167+
!else
1168+
1169+
$(RUBYDEF): $(LIBRUBY_A) $(RBCONFIG)
1170+
$(ECHO) generating $(@:\=/)
1171+
$(Q) $(LDSHARED) $(LIBRUBY_A) \
1172+
$(RUBY_SO_NAME).res $(SOLIBS) $(EXTSOLIBS) $(LIBS) \
1173+
$(OUTFLAG)$(@B).dll -link $(LDFLAGS) $(XLDFLAGS) \
1174+
$(EXTLDFLAGS) -implib:dummydef.lib \
1175+
-wholearchive:$(LIBRUBY_A) -map:$(@B).map -opt:noref -opt:noicf
1176+
$(Q) $(BOOTSTRAPRUBY_COMMAND) $(srcdir)/win32/mkexports.rb \
1177+
-output=$@ -arch=$(ARCH) $(@B).map
1178+
1179+
!endif
11651180

11661181
{$(win_srcdir)}.def.lib:
11671182
$(Q) $(AR) $(ARFLAGS)$@ -def:$<

win32/mkexports.rb

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module RbConfig
77
end
88

99
class Exports
10-
PrivateNames = /(?:Init_|InitVM_|ruby_static_id_|threadptr|_ec_|DllMain\b)/
10+
PrivateNames = /(?:\AInit_|\AInitVM_|\Aruby_static_id_|threadptr|_ec_|DllMain\b)/
1111

1212
def self.create(*args, &block)
1313
platform = RUBY_PLATFORM
@@ -96,20 +96,57 @@ def symbols()
9696

9797
class Exports::Mswin < Exports
9898
def each_line(objs, &block)
99-
IO.popen(%w"dumpbin -symbols -exports" + objs) do |f|
100-
f.each(&block)
99+
# IO.popen(%w"dumpbin -linkermember:1" + objs) do |f|
100+
objs.each do |o|
101+
open(o) do |f|
102+
f.each(&block)
103+
end
101104
end
102105
end
103106

104107
def each_export(objs)
105108
noprefix = ($arch ||= nil and /^(sh|i\d86)/ !~ $arch)
106109
objs = objs.collect {|s| s.tr('/', '\\')}
107-
filetype = nil
110+
libname = RbConfig::CONFIG["LIBRUBY_A"]
111+
libname[/\.lib$/]=""
112+
publics = false
113+
started = false
114+
finished = false
108115
objdump(objs) do |l|
109-
if (filetype = l[/^File Type: (.+)/, 1])..(/^\f/ =~ l)
110-
case filetype
116+
next if finished
117+
l.chomp!
118+
finished ||= started && l == ""
119+
started ||= publics && l != ""
120+
publics ||= /^\s+Address\s+Publics by Value\s+Rva\+Base\s+Lib:Object$/.match?(l)
121+
122+
if started
123+
/\A\s+\h+:\h+\s+(#{noprefix ? "" : "_"}[a-zA-Z_]\w+#{noprefix ? "" : /(?:@\d+)?/})\s+\h+(?:\s+(f)\s+|\s*)(?:#{libname}:[\w-]+\.[\w-]+|<common>)\z/.match(l) do |m|
124+
sym, f = m[1], m[2]
125+
if !noprefix && /^[@_]/.match?(sym) && !/@\d+$/.match?(sym)
126+
sym.sub!(/^[@_]/, '')
127+
end
128+
next if /\A_[^@]*\z|#{PrivateNames}/o.match?(sym)
129+
next if /@[[:xdigit:]]{8,32}\z/.match?(sym)
130+
yield sym, f != "f"
131+
end
132+
end
133+
next
134+
135+
symbols ||= /^\s*\d+\spublic symbols$/.match? l
136+
symbols &&= !(/^Archive member name/.match? l)
137+
if symbols
138+
l.chomp!
139+
next if l == ""
140+
141+
/^\s*\h+\s(#{noprefix ? "" : "_"}[a-zA-Z_]\w+)$/.match(l) do |m|
142+
is_data = ""
143+
next if /^_?#{PrivateNames}/o.match?(m[1])
144+
yield m[1], nil
145+
end
146+
next
147+
148+
case symbols
111149
when /OBJECT/, /LIBRARY/
112-
l.chomp!
113150
next if (/^ .*\(pick any\)$/ =~ l)...true
114151
next if /^[[:xdigit:]]+ 0+ UNDEF / =~ l
115152
next unless /External/ =~ l

0 commit comments

Comments
 (0)