Skip to content

Instantly share code, notes, and snippets.

package rs_test
import (
"fmt"
"reflect"
"testing"
)
type X interface {
Set(string)
package main
import (
"bytes"
"flag"
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
package main
import (
"flag"
"fmt"
"io"
"log"
"os"
"time"
)
#include <stdio.h>
#include <sys/mman.h>
#include <unistd.h>
#include <stdlib.h>
#include <err.h>
int
main(int argc, char **argv)
{
void *v = sbrk(4096);
@art4711
art4711 / gist:8008821
Last active August 7, 2019 17:12
Why not compiling with -fPIC matters.
To show why compiling without -fPIC still matters and why compilers don't default to -fPIC unless
it's strictly necessary:
$ cat > foo.c
int foo(void) { return 1; }
$ cat > bar.c
int foo(void);
int bar(void) { return foo(); }
$ cc -fPIC -c foo.c && cc -fPIC -c bar.c && cc -rdynamic -fPIC -shared -L . -o foobar.so foo.o bar.o
$ objdump -S foobar.so