From: Nathaniel Talbott Date: 2003-09-12T02:11:28+09:00 Subject: Re: Nested struct alignment summarized [LONG] Robert Feldt [mailto:feldt@ce.chalmers.se] wrote: > Below is code to assist analysis of this. I'd be interested > in the output from the script on other machines and with > other compilers. I've run it on a PC/WinXP/Cygwin Here are my results, as well as an updated version of the script that will work with MSVC. Nathaniel <:((>< Reporter: Nathaniel Talbott Email: nathaniel@NOSPAMtalbott.ws Ruby version: 1.8.0 (2003-08-04) [i386-mswin32] Compiler: cl Version: Microsoft Visual C++ Build command: cl -LD -o DLLNAME INPUTNAME -link -dll -export:o2o1 -expor t:i1o2 -export:i2i1 -export:o3i2 The address diffs are [4, 4, 4, 4] for all combinations but: ot2 char, ot1 char: [1, 3, 4, 4] it2 char, it1 char: [4, 4, 1, 3] ot2 char, ot1 short: [2, 2, 4, 4] it2 char, it1 short: [4, 4, 2, 2] ot2 char, ot1 double: [8, 4, 4, 4] it1 char, ot2 double: [8, 8, 4, 4] it2 char, it1 double: [4, 4, 8, 8] ot3 char, it2 double: [4, 4, 8, 8] ot2 int, ot1 double: [8, 4, 4, 4] it1 int, ot2 double: [8, 8, 4, 4] it2 int, it1 double: [4, 4, 8, 8] ot3 int, it2 double: [4, 4, 8, 8] ot2 short, ot1 char: [2, 2, 4, 4] it2 short, it1 char: [4, 4, 2, 2] ot2 short, ot1 short: [2, 2, 4, 4] it2 short, it1 short: [4, 4, 2, 2] ot2 short, ot1 double: [8, 4, 4, 4] it1 short, ot2 double: [8, 8, 4, 4] it2 short, it1 double: [4, 4, 8, 8] ot3 short, it2 double: [4, 4, 8, 8] ot2 long, ot1 double: [8, 4, 4, 4] it1 long, ot2 double: [8, 8, 4, 4] it2 long, it1 double: [4, 4, 8, 8] ot3 long, it2 double: [4, 4, 8, 8] ot2 void*, ot1 double: [8, 4, 4, 4] it1 void*, ot2 double: [8, 8, 4, 4] it2 void*, it1 double: [4, 4, 8, 8] ot3 void*, it2 double: [4, 4, 8, 8] ot2 float, ot1 double: [8, 4, 4, 4] it1 float, ot2 double: [8, 8, 4, 4] it2 float, it1 double: [4, 4, 8, 8] ot3 float, it2 double: [4, 4, 8, 8] ot2 double, ot1 char: [8, 8, 4, 4] it1 double, ot2 char: [4, 4, 8, 8] it2 double, it1 char: [4, 4, 8, 8] ot2 double, ot1 int: [8, 8, 4, 4] it1 double, ot2 int: [4, 4, 8, 8] it2 double, it1 int: [4, 4, 8, 8] ot2 double, ot1 short: [8, 8, 4, 4] it1 double, ot2 short: [4, 4, 8, 8] it2 double, it1 short: [4, 4, 8, 8] ot2 double, ot1 long: [8, 8, 4, 4] it1 double, ot2 long: [4, 4, 8, 8] it2 double, it1 long: [4, 4, 8, 8] ot2 double, ot1 void*: [8, 8, 4, 4] it1 double, ot2 void*: [4, 4, 8, 8] it2 double, it1 void*: [4, 4, 8, 8] ot2 double, ot1 float: [8, 8, 4, 4] it1 double, ot2 float: [4, 4, 8, 8] it2 double, it1 float: [4, 4, 8, 8] ot2 double, ot1 double: [8, 8, 4, 4] it1 double, ot2 double: [8, 8, 8, 8] it2 double, it1 double: [4, 4, 8, 8] ot3 double, it2 double: [4, 4, 8, 8] alignment.rb: require 'dl/import' require 'dl/struct' your_name, your_mail = ARGV[0], ARGV[1] compiler = ARGV[2] || "gcc" MSVC = (compiler == 'cl') compile_cmd = ARGV[3] || (MSVC ? "-nologo -LD -o DLLNAME INPUTNAME -link -dll -export:o2o1 -export:i1o2 -export:i2i1 -export:o3i2" : "-shared -o DLLNAME INPUTNAME") version_cmd = ARGV[4] || "--version" class CFile def initialize(compiler, compileCommand, versionCommand) @co, @cc, @vc = compiler, compileCommand, versionCommand @count = 0 end def compile_to_dll(dllname = "test.so", code = "", cfilename = "test.c") File.open(cfilename, "w") {|fh| fh.write code} cmd = "#{@co} #{@cc}".gsub("DLLNAME", dllname).gsub("INPUTNAME", cfilename) system cmd File.delete cfilename end def compiler_version MSVC ? "Microsoft Visual C++" : `#{@co} #{@vc}` end Template = < tfrst, t2 => tsnd} adiffs = cf.address_diffs(th) results << ["#{t1} #{tfrst}, #{t2} #{tsnd}:", adiffs] counts[adiffs] += 1 STDERR.print "."; STDERR.flush end end most_common = counts.to_a.sort {|a,b| b.last <=> a.last}.first.first puts puts puts report puts "The address diffs are #{most_common.inspect} for all combinations but:" # Print the uncommon ones results.each {|r| puts "#{r[0]} #{r[1].inspect}" unless r[1] == most_common}