*NIX & Hacking —— 第3期

做一本我感兴趣的杂志,就这么简单!

D

Lessons Learned: Writing a filesystem in D

Golang

An Exercise in Profiling a Go Program
Let’s learn Go!

Javascript

jsbeeb

Kernel

Build a Red Hat 7 custom kernel
How to Compile Linux Kernel from Source to Build Custom Kernel

Scala

Difference between object and class in Scala

Security

Introducing s2n, a New Open Source TLS Implementation

Unix

Solaris new system calls: getentropy(2) and getrandom(2)
websocketd
When ‘int’ is the new ‘short’

Virtualization

Understanding VT-d: Intel Virtualization Technology for Directed I/O

Easter egg

FUDCON PUNE 2015
Multiple choice
What is the difference between x64 and IA-64?

在Linux上搭建D语言开发环境

本文介绍如何在Linux上搭建D语言的开发环境:

(1)编译器我选的是gdc,从官方网站下载适合机器的版本,直接解压缩就可以了(不要解压到系统root文件夹:”/“)。为了方便起见,可以把路径加到PATH环境变量:

export PATH=$PWD/x86_64-gdcproject-linux-gnu/bin:$PATH

接下来写个简单的“hello world”程序(hello.d):

import std.stdio;
void main()
{
    writeln("Hello World!");
}  

编译一下:

[root@localhost nan]# gdc hello.d -o hello
/usr/bin/ld: unrecognized option '-plugin'
/usr/bin/ld: use the --help option for usage information
collect2: error: ld returned 1 exit status

这个问题的解决办法是在编译时加上“-fno-use-linker-plugin”选项。再次编译:

[root@localhost nan]# gdc -fno-use-linker-plugin -g hello.d -o hello
[root@localhost nan]# 

成功!
运行一下:

[root@localhost nan]# ./hello
Hello World!

输出了“Hello World!”。

(2)使用gdb进行调试。
示例程序代码如下:

import std.stdio;

void main()
{
    int sum;
    int i;

    for (i = 1; i <= 10; i++)
    {
        sum += i;
    }

    writeln(sum);
}

编译时需要加上“-g”编译选项,产生调试信息:

gdc -fno-use-linker-plugin -g sum.d -o sum

开始调试:

[root@localhost nan]# gdb -q sum
Reading symbols from sum...done.
(gdb) start
Temporary breakpoint 1 at 0x4057bf: file sum.d, line 5.
Starting program: /home/nan/sum
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".

Temporary breakpoint 1, D main () at sum.d:5
5               int sum;
(gdb) n
6               int i;
(gdb)
8               for (i = 1; i <= 10; i++)
(gdb)
10                      sum += i;
(gdb)
8               for (i = 1; i <= 10; i++)
(gdb) p i
$1 = 1
(gdb) p sum
$2 = 1
(gdb) c
Continuing.
55
[Inferior 1 (process 41619) exited normally]

可以看到,和调试普通的C程序没什么区别。

参考资料:
(1)How to fix “unrecognized option ‘-plugin`” when using gdc to compile D program?
(2)GDC documentation and debugging problems