changeset ffe6ab7141ab in /z/repo/gem5
details: http://repo.gem5.org/gem5?cmd=changeset;node=ffe6ab7141ab
description:
        x86: Fixes to avoid LTO warnings

        This patch fixes a few minor issues that caused link-time warnings
        when using LTO, mainly for x86. The most important change is how the
        syscall array is created. Previously gcc and clang would complain that
        the declaration and definition types did not match. The organisation
        is now changed to match how it is done for ARM, moving the code that
        was previously in syscalls.cc into process.cc, and having a class
        variable pointing to the static array.

        With these changes, there are no longer any warnings using gcc 4.6.3
        with LTO.

diffstat:

 src/arch/x86/SConscript        |    1 -
 src/arch/x86/linux/process.cc  |  778 ++++++++++++++++++++++++++++++++++++++-
 src/arch/x86/linux/process.hh  |   10 -
 src/arch/x86/linux/syscalls.cc |  822 -----------------------------------------
 src/sim/system.cc              |    9 +-
 src/sim/system.hh              |   10 +-
 6 files changed, 792 insertions(+), 838 deletions(-)

diffs (truncated from 1720 to 300 lines):

diff -r 9277177eccff -r ffe6ab7141ab src/arch/x86/SConscript
--- a/src/arch/x86/SConscript   Mon Oct 20 18:03:55 2014 -0400
+++ b/src/arch/x86/SConscript   Mon Oct 20 18:03:56 2014 -0400
@@ -59,7 +59,6 @@
     Source('isa.cc')
     Source('linux/linux.cc')
     Source('linux/process.cc')
-    Source('linux/syscalls.cc')
     Source('linux/system.cc')
     Source('nativetrace.cc')
     Source('pagetable.cc')
diff -r 9277177eccff -r ffe6ab7141ab src/arch/x86/linux/process.cc
--- a/src/arch/x86/linux/process.cc     Mon Oct 20 18:03:55 2014 -0400
+++ b/src/arch/x86/linux/process.cc     Mon Oct 20 18:03:56 2014 -0400
@@ -37,6 +37,7 @@
  * Authors: Gabe Black
  */
 
+#include "arch/x86/linux/linux.hh"
 #include "arch/x86/linux/process.hh"
 #include "arch/x86/isa_traits.hh"
 #include "arch/x86/registers.hh"
@@ -44,16 +45,789 @@
 #include "cpu/thread_context.hh"
 #include "kern/linux/linux.hh"
 #include "sim/process.hh"
+#include "sim/syscall_emul.hh"
 
 using namespace std;
 using namespace X86ISA;
 
+/// Target uname() handler.
+static SyscallReturn
+unameFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
+          ThreadContext *tc)
+{
+    int index = 0;
+    TypedBufferArg<Linux::utsname> name(process->getSyscallArg(tc, index));
+
+    strcpy(name->sysname, "Linux");
+    strcpy(name->nodename, "sim.gem5.org");
+    strcpy(name->release, "3.0.0");
+    strcpy(name->version, "#1 Mon Aug 18 11:32:15 EDT 2003");
+    strcpy(name->machine, "x86_64");
+
+    name.copyOut(tc->getMemProxy());
+
+    return 0;
+}
+
+static SyscallReturn
+archPrctlFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
+              ThreadContext *tc)
+{
+    enum ArchPrctlCodes
+    {
+        SetFS = 0x1002,
+        GetFS = 0x1003,
+        SetGS = 0x1001,
+        GetGS = 0x1004
+    };
+
+    //First argument is the code, second is the address
+    int index = 0;
+    int code = process->getSyscallArg(tc, index);
+    uint64_t addr = process->getSyscallArg(tc, index);
+    uint64_t fsBase, gsBase;
+    SETranslatingPortProxy &p = tc->getMemProxy();
+    switch(code)
+    {
+      //Each of these valid options should actually check addr.
+      case SetFS:
+        tc->setMiscRegNoEffect(MISCREG_FS_BASE, addr);
+        tc->setMiscRegNoEffect(MISCREG_FS_EFF_BASE, addr);
+        return 0;
+      case GetFS:
+        fsBase = tc->readMiscRegNoEffect(MISCREG_FS_BASE);
+        p.write(addr, fsBase);
+        return 0;
+      case SetGS:
+        tc->setMiscRegNoEffect(MISCREG_GS_BASE, addr);
+        tc->setMiscRegNoEffect(MISCREG_GS_EFF_BASE, addr);
+        return 0;
+      case GetGS:
+        gsBase = tc->readMiscRegNoEffect(MISCREG_GS_BASE);
+        p.write(addr, gsBase);
+        return 0;
+      default:
+        return -EINVAL;
+    }
+}
+
+BitUnion32(UserDescFlags)
+    Bitfield<0> seg_32bit;
+    Bitfield<2, 1> contents;
+    Bitfield<3> read_exec_only;
+    Bitfield<4> limit_in_pages;
+    Bitfield<5> seg_not_present;
+    Bitfield<6> useable;
+EndBitUnion(UserDescFlags)
+
+struct UserDesc32 {
+    uint32_t entry_number;
+    uint32_t base_addr;
+    uint32_t limit;
+    uint32_t flags;
+};
+
+struct UserDesc64 {
+    uint32_t entry_number;
+    uint32_t __padding1;
+    uint64_t base_addr;
+    uint32_t limit;
+    uint32_t flags;
+};
+
+static SyscallReturn
+setThreadArea32Func(SyscallDesc *desc, int callnum,
+        LiveProcess *process, ThreadContext *tc)
+{
+    const int minTLSEntry = 6;
+    const int numTLSEntries = 3;
+    const int maxTLSEntry = minTLSEntry + numTLSEntries - 1;
+
+    X86LiveProcess *x86lp = dynamic_cast<X86LiveProcess *>(process);
+    assert(x86lp);
+
+    assert((maxTLSEntry + 1) * sizeof(uint64_t) <= x86lp->gdtSize());
+
+    int argIndex = 0;
+    TypedBufferArg<UserDesc32> userDesc(process->getSyscallArg(tc, argIndex));
+    TypedBufferArg<uint64_t>
+        gdt(x86lp->gdtStart() + minTLSEntry * sizeof(uint64_t),
+                numTLSEntries * sizeof(uint64_t));
+
+    if (!userDesc.copyIn(tc->getMemProxy()))
+        return -EFAULT;
+
+    if (!gdt.copyIn(tc->getMemProxy()))
+        panic("Failed to copy in GDT for %s.\n", desc->name);
+
+    if (userDesc->entry_number == (uint32_t)(-1)) {
+        // Find a free TLS entry.
+        for (int i = 0; i < numTLSEntries; i++) {
+            if (gdt[i] == 0) {
+                userDesc->entry_number = i + minTLSEntry;
+                break;
+            }
+        }
+        // We failed to find one.
+        if (userDesc->entry_number == (uint32_t)(-1))
+            return -ESRCH;
+    }
+
+    int index = userDesc->entry_number;
+
+    if (index < minTLSEntry || index > maxTLSEntry)
+        return -EINVAL;
+
+    index -= minTLSEntry;
+
+    // Build the entry we're going to add.
+    SegDescriptor segDesc = 0;
+    UserDescFlags flags = userDesc->flags;
+
+    segDesc.limitLow = bits(userDesc->limit, 15, 0);
+    segDesc.baseLow = bits(userDesc->base_addr, 23, 0);
+    segDesc.type.a = 1;
+    if (!flags.read_exec_only)
+        segDesc.type.w = 1;
+    if (bits((uint8_t)flags.contents, 0))
+        segDesc.type.e = 1;
+    if (bits((uint8_t)flags.contents, 1))
+        segDesc.type.codeOrData = 1;
+    segDesc.s = 1;
+    segDesc.dpl = 3;
+    if (!flags.seg_not_present)
+        segDesc.p = 1;
+    segDesc.limitHigh = bits(userDesc->limit, 19, 16);
+    if (flags.useable)
+        segDesc.avl = 1;
+    segDesc.l = 0;
+    if (flags.seg_32bit)
+        segDesc.d = 1;
+    if (flags.limit_in_pages)
+        segDesc.g = 1;
+    segDesc.baseHigh = bits(userDesc->base_addr, 31, 24);
+
+    gdt[index] = (uint64_t)segDesc;
+
+    if (!userDesc.copyOut(tc->getMemProxy()))
+        return -EFAULT;
+    if (!gdt.copyOut(tc->getMemProxy()))
+        panic("Failed to copy out GDT for %s.\n", desc->name);
+
+    return 0;
+}
+
+static SyscallDesc syscallDescs64[] = {
+    /*   0 */ SyscallDesc("read", readFunc),
+    /*   1 */ SyscallDesc("write", writeFunc),
+    /*   2 */ SyscallDesc("open", openFunc<X86Linux64>),
+    /*   3 */ SyscallDesc("close", closeFunc),
+    /*   4 */ SyscallDesc("stat", stat64Func<X86Linux64>),
+    /*   5 */ SyscallDesc("fstat", fstat64Func<X86Linux64>),
+    /*   6 */ SyscallDesc("lstat", lstat64Func<X86Linux64>),
+    /*   7 */ SyscallDesc("poll", unimplementedFunc),
+    /*   8 */ SyscallDesc("lseek", lseekFunc),
+    /*   9 */ SyscallDesc("mmap", mmapFunc<X86Linux64>),
+    /*  10 */ SyscallDesc("mprotect", ignoreFunc),
+    /*  11 */ SyscallDesc("munmap", munmapFunc),
+    /*  12 */ SyscallDesc("brk", brkFunc),
+    /*  13 */ SyscallDesc("rt_sigaction", ignoreFunc),
+    /*  14 */ SyscallDesc("rt_sigprocmask", ignoreFunc),
+    /*  15 */ SyscallDesc("rt_sigreturn", unimplementedFunc),
+    /*  16 */ SyscallDesc("ioctl", ioctlFunc<X86Linux64>),
+    /*  17 */ SyscallDesc("pread64", unimplementedFunc),
+    /*  18 */ SyscallDesc("pwrite64", unimplementedFunc),
+    /*  19 */ SyscallDesc("readv", unimplementedFunc),
+    /*  20 */ SyscallDesc("writev", writevFunc<X86Linux64>),
+    /*  21 */ SyscallDesc("access", ignoreFunc),
+    /*  22 */ SyscallDesc("pipe", unimplementedFunc),
+    /*  23 */ SyscallDesc("select", unimplementedFunc),
+    /*  24 */ SyscallDesc("sched_yield", unimplementedFunc),
+    /*  25 */ SyscallDesc("mremap", mremapFunc<X86Linux64>),
+    /*  26 */ SyscallDesc("msync", unimplementedFunc),
+    /*  27 */ SyscallDesc("mincore", unimplementedFunc),
+    /*  28 */ SyscallDesc("madvise", unimplementedFunc),
+    /*  29 */ SyscallDesc("shmget", unimplementedFunc),
+    /*  30 */ SyscallDesc("shmat", unimplementedFunc),
+    /*  31 */ SyscallDesc("shmctl", unimplementedFunc),
+    /*  32 */ SyscallDesc("dup", dupFunc),
+    /*  33 */ SyscallDesc("dup2", unimplementedFunc),
+    /*  34 */ SyscallDesc("pause", unimplementedFunc),
+    /*  35 */ SyscallDesc("nanosleep", unimplementedFunc),
+    /*  36 */ SyscallDesc("getitimer", unimplementedFunc),
+    /*  37 */ SyscallDesc("alarm", unimplementedFunc),
+    /*  38 */ SyscallDesc("setitimer", unimplementedFunc),
+    /*  39 */ SyscallDesc("getpid", getpidFunc),
+    /*  40 */ SyscallDesc("sendfile", unimplementedFunc),
+    /*  41 */ SyscallDesc("socket", unimplementedFunc),
+    /*  42 */ SyscallDesc("connect", unimplementedFunc),
+    /*  43 */ SyscallDesc("accept", unimplementedFunc),
+    /*  44 */ SyscallDesc("sendto", unimplementedFunc),
+    /*  45 */ SyscallDesc("recvfrom", unimplementedFunc),
+    /*  46 */ SyscallDesc("sendmsg", unimplementedFunc),
+    /*  47 */ SyscallDesc("recvmsg", unimplementedFunc),
+    /*  48 */ SyscallDesc("shutdown", unimplementedFunc),
+    /*  49 */ SyscallDesc("bind", unimplementedFunc),
+    /*  50 */ SyscallDesc("listen", unimplementedFunc),
+    /*  51 */ SyscallDesc("getsockname", unimplementedFunc),
+    /*  52 */ SyscallDesc("getpeername", unimplementedFunc),
+    /*  53 */ SyscallDesc("socketpair", unimplementedFunc),
+    /*  54 */ SyscallDesc("setsockopt", unimplementedFunc),
+    /*  55 */ SyscallDesc("getsockopt", unimplementedFunc),
+    /*  56 */ SyscallDesc("clone", cloneFunc),
+    /*  57 */ SyscallDesc("fork", unimplementedFunc),
+    /*  58 */ SyscallDesc("vfork", unimplementedFunc),
+    /*  59 */ SyscallDesc("execve", unimplementedFunc),
+    /*  60 */ SyscallDesc("exit", exitFunc),
+    /*  61 */ SyscallDesc("wait4", unimplementedFunc),
+    /*  62 */ SyscallDesc("kill", unimplementedFunc),
+    /*  63 */ SyscallDesc("uname", unameFunc),
+    /*  64 */ SyscallDesc("semget", unimplementedFunc),
+    /*  65 */ SyscallDesc("semop", unimplementedFunc),
+    /*  66 */ SyscallDesc("semctl", unimplementedFunc),
+    /*  67 */ SyscallDesc("shmdt", unimplementedFunc),
+    /*  68 */ SyscallDesc("msgget", unimplementedFunc),
+    /*  69 */ SyscallDesc("msgsnd", unimplementedFunc),
+    /*  70 */ SyscallDesc("msgrcv", unimplementedFunc),
+    /*  71 */ SyscallDesc("msgctl", unimplementedFunc),
+    /*  72 */ SyscallDesc("fcntl", fcntlFunc),
+    /*  73 */ SyscallDesc("flock", unimplementedFunc),
+    /*  74 */ SyscallDesc("fsync", unimplementedFunc),
+    /*  75 */ SyscallDesc("fdatasync", unimplementedFunc),
+    /*  76 */ SyscallDesc("truncate", truncateFunc),
+    /*  77 */ SyscallDesc("ftruncate", ftruncateFunc),
+    /*  78 */ SyscallDesc("getdents", getdentsFunc),
+    /*  79 */ SyscallDesc("getcwd", getcwdFunc),
+    /*  80 */ SyscallDesc("chdir", unimplementedFunc),
+    /*  81 */ SyscallDesc("fchdir", unimplementedFunc),
+    /*  82 */ SyscallDesc("rename", renameFunc),
+    /*  83 */ SyscallDesc("mkdir", unimplementedFunc),
+    /*  84 */ SyscallDesc("rmdir", unimplementedFunc),
+    /*  85 */ SyscallDesc("creat", unimplementedFunc),
+    /*  86 */ SyscallDesc("link", unimplementedFunc),
+    /*  87 */ SyscallDesc("unlink", unlinkFunc),
+    /*  88 */ SyscallDesc("symlink", unimplementedFunc),
+    /*  89 */ SyscallDesc("readlink", readlinkFunc),
+    /*  90 */ SyscallDesc("chmod", unimplementedFunc),
+    /*  91 */ SyscallDesc("fchmod", unimplementedFunc),
+    /*  92 */ SyscallDesc("chown", unimplementedFunc),
+    /*  93 */ SyscallDesc("fchown", unimplementedFunc),
+    /*  94 */ SyscallDesc("lchown", unimplementedFunc),
+    /*  95 */ SyscallDesc("umask", unimplementedFunc),
+    /*  96 */ SyscallDesc("gettimeofday", gettimeofdayFunc<X86Linux64>),
+    /*  97 */ SyscallDesc("getrlimit", getrlimitFunc<X86Linux64>),
+    /*  98 */ SyscallDesc("getrusage", getrusageFunc<X86Linux64>),
+    /*  99 */ SyscallDesc("sysinfo", sysinfoFunc<X86Linux64>),
+    /* 100 */ SyscallDesc("times", timesFunc<X86Linux64>),
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to